Vladislav.Soroka
2014-02-10 17:13:08 +04:00
parent 5c74ffe031
commit 58c879183e
10 changed files with 539 additions and 215 deletions
@@ -25,7 +25,10 @@ import com.intellij.util.containers.ContainerUtil;
import org.gradle.tooling.model.idea.IdeaModule;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.plugins.gradle.model.WebConfiguration;
import org.jetbrains.plugins.gradle.model.data.War;
import org.jetbrains.plugins.gradle.model.data.WarDirectory;
import org.jetbrains.plugins.gradle.model.data.WebConfigurationModelData;
import org.jetbrains.plugins.gradle.model.data.WebResource;
import org.jetbrains.plugins.gradle.service.project.AbstractProjectResolverExtension;
import org.jetbrains.plugins.gradle.util.GradleConstants;
@@ -47,13 +50,14 @@ public class JavaEEGradleProjectResolverExtension extends AbstractProjectResolve
public void populateModuleExtraModels(@NotNull IdeaModule gradleModule, @NotNull DataNode<ModuleData> ideModule) {
final WebConfiguration webConfiguration = resolverCtx.getExtraProject(gradleModule, WebConfiguration.class);
if (webConfiguration != null) {
List<WebConfigurationModelData.War> warModels =
ContainerUtil.map(webConfiguration.getWarModels(), new Function<WebConfiguration.WarModel, WebConfigurationModelData.War>() {
List<War> warModels =
ContainerUtil.map(webConfiguration.getWarModels(), new Function<WebConfiguration.WarModel, War>() {
@Override
public WebConfigurationModelData.War fun(WebConfiguration.WarModel model) {
WebConfigurationModelData.War war = new WebConfigurationModelData.War(model.getWarName(), model.getWebAppDirName(), model.getWebAppDir());
public War fun(WebConfiguration.WarModel model) {
War war =
new War(model.getWarName(), model.getWebAppDirName(), model.getWebAppDir());
war.setWebXml(model.getWebXml());
war.setWebRoots(model.getWebRoots());
war.setWebResources(map(model.getWebResources()));
war.setClasspath(model.getClasspath());
war.setManifestContent(model.getManifestContent());
return war;
@@ -71,4 +75,18 @@ public class JavaEEGradleProjectResolverExtension extends AbstractProjectResolve
public Set<Class> getExtraProjectModelClasses() {
return Collections.<Class>singleton(WebConfiguration.class);
}
private static List<WebResource> map(List<WebConfiguration.WebResource> webResources) {
return ContainerUtil.mapNotNull(webResources, new Function<WebConfiguration.WebResource, WebResource>() {
@Override
public WebResource fun(WebConfiguration.WebResource resource) {
if (resource == null) return null;
final WarDirectory warDirectory =
WarDirectory.fromPath(resource.getWarDirectory());
if (warDirectory == null) return null;
return new WebResource(warDirectory, resource.getRelativePath(), resource.getFile());
}
});
}
}
@@ -0,0 +1,142 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.plugins.gradle.model.data;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.io.File;
import java.util.Collections;
import java.util.List;
import java.util.Set;
/**
* @author Vladislav.Soroka
* @since 2/10/14
*/
public class War {
@NotNull
private final String myName;
@NotNull
private final String myWebAppDirName;
@NotNull
private final File myWebAppDir;
@Nullable
private File myWebXml;
@NotNull
private List<WebResource> myWebResources;
@NotNull
private Set<File> myClasspath;
@Nullable
private String myManifestContent;
public War(@NotNull String name, @NotNull String webAppDirName, @NotNull File webAppDir) {
myName = name;
myWebAppDirName = webAppDirName;
myWebAppDir = webAppDir;
myWebResources = Collections.emptyList();
myClasspath = Collections.emptySet();
}
@NotNull
public String getName() {
return myName;
}
@NotNull
public String getWebAppDirName() {
return myWebAppDirName;
}
@NotNull
public File getWebAppDir() {
return myWebAppDir;
}
public void setWebXml(@Nullable File webXml) {
myWebXml = webXml;
}
@Nullable
public File getWebXml() {
return myWebXml;
}
public void setWebResources(@Nullable List<WebResource> webResources) {
myWebResources = webResources == null ? Collections.<WebResource>emptyList() : webResources;
}
@NotNull
public List<WebResource> getWebResources() {
return myWebResources;
}
public void setClasspath(@Nullable Set<File> classpath) {
myClasspath = classpath == null ? Collections.<File>emptySet() : classpath;
}
@NotNull
public Set<File> getClasspath() {
return myClasspath;
}
public void setManifestContent(@Nullable String manifestContent) {
myManifestContent = manifestContent;
}
@Nullable
public String getManifestContent() {
return myManifestContent;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (!super.equals(o)) return false;
War that = (War)o;
if (!myName.equals(that.myName)) return false;
if (!myWebAppDirName.equals(that.myWebAppDirName)) return false;
if (!myWebResources.equals(that.myWebResources)) return false;
return true;
}
@Override
public int hashCode() {
int result = super.hashCode();
result = 31 * result + myName.hashCode();
result = 31 * result + myWebAppDirName.hashCode();
result = 31 * result + myWebResources.hashCode();
return result;
}
@Override
public String toString() {
return "War{" +
"myName='" + myName + '\'' +
", myWebAppDirName='" + myWebAppDirName + '\'' +
", myWebAppDir=" + myWebAppDir +
", myWebXml=" + myWebXml +
", myWebResources=" + myWebResources +
'}';
}
}
@@ -0,0 +1,75 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.plugins.gradle.model.data;
import com.intellij.openapi.util.text.StringUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* @author Vladislav.Soroka
* @since 2/10/14
*/
public enum WarDirectory {
/**
* Public files typically include the following:
* HTML files.
* JSP files.
* Image files and other multimedia files -- it is a common convention to store image files in an images subdirectory.
*/
WAR_ROOT("/"),
/**
* directory can contain the following file:
* META-INF/MANIFEST.MF -- an optional file that can be used to specify additional meta-information for the WAR.
*/
META_INF("/META-INF"),
/**
* Directory contains a Web archive's private files and directories.
* That is, when the Web archive is deployed, the files and directories under the WEB-INF/ directory cannot be accessed directly by Web clients.
*/
WEB_INF("/WEB-INF"),
/**
* Subdirectory can store JAR files used by the Web module.
* The JAR files in this directory are automatically accessible to the Web module without needing to be added to the class path.
*/
WEB_INF_LIB("/WEB-INF/lib"),
/**
* Subdirectory contains the compiled Java code for the Web module.
*/
WEB_INF_CLASSES("/WEB-INF/classes");
@NotNull
private final String myRelativePath;
WarDirectory(@NotNull final String relativePath) {
myRelativePath = relativePath;
}
@NotNull
public String getRelativePath() {
return myRelativePath;
}
@Nullable
public static WarDirectory fromPath(final @NotNull String path) {
if (StringUtil.isEmpty(path)) return WAR_ROOT;
final String adjustedPath = path.charAt(0) != '/' ? '/' + path : path;
for (WarDirectory warDirectory : values()) {
if (warDirectory.myRelativePath.equals(adjustedPath)) return warDirectory;
}
return null;
}
}
@@ -20,13 +20,8 @@ import com.intellij.openapi.externalSystem.model.ProjectKeys;
import com.intellij.openapi.externalSystem.model.ProjectSystemId;
import com.intellij.openapi.externalSystem.model.project.AbstractExternalEntityData;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.io.File;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
* @author Vladislav.Soroka
@@ -36,7 +31,8 @@ public class WebConfigurationModelData extends AbstractExternalEntityData {
private static final long serialVersionUID = 1L;
@NotNull
public static final Key<WebConfigurationModelData> KEY = Key.create(WebConfigurationModelData.class, ProjectKeys.LIBRARY_DEPENDENCY.getProcessingWeight() + 1);
public static final Key<WebConfigurationModelData> KEY =
Key.create(WebConfigurationModelData.class, ProjectKeys.LIBRARY_DEPENDENCY.getProcessingWeight() + 1);
@NotNull
private final List<War> myWars;
@@ -51,120 +47,6 @@ public class WebConfigurationModelData extends AbstractExternalEntityData {
return myWars;
}
public static class War {
@NotNull
private final String myName;
@NotNull
private final String myWebAppDirName;
@NotNull
private final File myWebAppDir;
@Nullable
private File myWebXml;
@NotNull
private Map<String, Set<String>> myWebRoots;
@NotNull
private Set<File> myClasspath;
@Nullable
private String myManifestContent;
public War(@NotNull String name, @NotNull String webAppDirName, @NotNull File webAppDir) {
myName = name;
myWebAppDirName = webAppDirName;
myWebAppDir = webAppDir;
myWebRoots = Collections.emptyMap();
myClasspath = Collections.emptySet();
}
@NotNull
public String getName() {
return myName;
}
@NotNull
public String getWebAppDirName() {
return myWebAppDirName;
}
@NotNull
public File getWebAppDir() {
return myWebAppDir;
}
public void setWebXml(@Nullable File webXml) {
myWebXml = webXml;
}
@Nullable
public File getWebXml() {
return myWebXml;
}
public void setWebRoots(@Nullable Map<String, Set<String>> webRoots) {
myWebRoots = webRoots == null ? Collections.<String, Set<String>>emptyMap() : webRoots;
}
@NotNull
public Map<String, Set<String>> getWebRoots() {
return myWebRoots;
}
public void setClasspath(@Nullable Set<File> classpath) {
myClasspath = classpath == null ? Collections.<File>emptySet() : classpath;
}
@NotNull
public Set<File> getClasspath() {
return myClasspath;
}
public void setManifestContent(@Nullable String manifestContent) {
myManifestContent = manifestContent;
}
@Nullable
public String getManifestContent() {
return myManifestContent;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (!super.equals(o)) return false;
War that = (War)o;
if (!myName.equals(that.myName)) return false;
if (!myWebAppDirName.equals(that.myWebAppDirName)) return false;
if (!myWebRoots.equals(that.myWebRoots)) return false;
return true;
}
@Override
public int hashCode() {
int result = super.hashCode();
result = 31 * result + myName.hashCode();
result = 31 * result + myWebAppDirName.hashCode();
result = 31 * result + myWebRoots.hashCode();
return result;
}
@Override
public String toString() {
return "War{" +
"myName='" + myName + '\'' +
", myWebAppDirName='" + myWebAppDirName + '\'' +
", myWebAppDir=" + myWebAppDir +
", myWebXml=" + myWebXml +
", myWebRoots=" + myWebRoots +
'}';
}
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
@@ -0,0 +1,84 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.plugins.gradle.model.data;
import org.jetbrains.annotations.NotNull;
import java.io.File;
/**
* @author Vladislav.Soroka
* @since 2/10/14
*/
public class WebResource {
@NotNull
private final WarDirectory myWarDirectory;
@NotNull
private final String warRelativePath;
@NotNull
private final File file;
public WebResource(@NotNull WarDirectory warDirectory, @NotNull String warRelativePath, @NotNull File file) {
myWarDirectory = warDirectory;
this.warRelativePath = warRelativePath;
this.file = file;
}
@NotNull
public WarDirectory getWarDirectory() {
return myWarDirectory;
}
@NotNull
public String getWarRelativePath() {
return warRelativePath;
}
@NotNull
public File getFile() {
return file;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof WebResource)) return false;
WebResource resource = (WebResource)o;
if (!file.getPath().equals(resource.file.getPath())) return false;
if (myWarDirectory != resource.myWarDirectory) return false;
if (!warRelativePath.equals(resource.warRelativePath)) return false;
return true;
}
@Override
public int hashCode() {
int result = myWarDirectory.hashCode();
result = 31 * result + warRelativePath.hashCode();
result = 31 * result + file.getPath().hashCode();
return result;
}
@Override
public String toString() {
return "WebResource{" +
"myWarDirectory=" + myWarDirectory +
", warRelativePath='" + warRelativePath + '\'' +
", file=" + file +
'}';
}
}
@@ -27,11 +27,14 @@ import org.gradle.api.tasks.bundling.War;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.plugins.gradle.model.WebConfiguration;
import org.jetbrains.plugins.gradle.tooling.ModelBuilderService;
import org.jetbrains.plugins.gradle.tooling.internal.WarModelImpl;
import org.jetbrains.plugins.gradle.tooling.internal.WebConfigurationImpl;
import org.jetbrains.plugins.gradle.tooling.internal.WebResourceImpl;
import java.io.File;
import java.io.StringWriter;
import java.util.*;
import java.util.ArrayList;
import java.util.List;
/**
* @author Vladislav.Soroka
@@ -66,14 +69,13 @@ public class WarModelBuilderImpl implements ModelBuilderService {
for (Task task : project.getTasks()) {
if (task instanceof War) {
final WebConfigurationImpl.WarModelImpl warModel = new WebConfigurationImpl.WarModelImpl(((War)task).getArchiveName(), webAppDirName, webAppDir);
final WarModelImpl warModel =
new WarModelImpl(((War)task).getArchiveName(), webAppDirName, webAppDir);
final List<WebConfiguration.WebResource> webResources = new ArrayList<WebConfiguration.WebResource>();
final War warTask = (War)task;
warModel.setWebXml(warTask.getWebXml());
final Map<String, Set<String>> webRoots = new HashMap<String, Set<String>>();
addPath(webRoots, "", webAppDir.getPath());
warTask.getRootSpec().walk(new Action<CopySpecInternal>() {
@Override
public void execute(CopySpecInternal internal) {
@@ -82,7 +84,7 @@ public class WarModelBuilderImpl implements ModelBuilderService {
@Override
public void visitDir(FileVisitDetails dirDetails) {
try {
addPath(webRoots, relativePath, dirDetails.getFile().getPath());
addPath(webResources, relativePath, dirDetails.getPath(), dirDetails.getFile());
}
catch (Exception ignore) {
}
@@ -93,7 +95,7 @@ public class WarModelBuilderImpl implements ModelBuilderService {
try {
if (warTask.getWebXml() == null ||
!fileDetails.getFile().getCanonicalPath().equals(warTask.getWebXml().getCanonicalPath())) {
addPath(webRoots, relativePath, fileDetails.getFile().getParent());
addPath(webResources, relativePath, fileDetails.getPath(), fileDetails.getFile());
}
}
catch (Exception ignore) {
@@ -103,11 +105,11 @@ public class WarModelBuilderImpl implements ModelBuilderService {
}
});
warModel.setWebRoots(webRoots);
warModel.setWebResources(webResources);
warModel.setClasspath(warTask.getClasspath().getFiles());
Manifest manifest = warTask.getManifest();
if(manifest != null) {
if (manifest != null) {
StringWriter writer = new StringWriter();
manifest.writeTo(writer);
warModel.setManifestContent(writer.toString());
@@ -119,13 +121,10 @@ public class WarModelBuilderImpl implements ModelBuilderService {
return new WebConfigurationImpl(warModels);
}
private static void addPath(Map<String, Set<String>> webRoots, String relativePath, String path) {
relativePath = relativePath == null ? "" : relativePath;
Set<String> paths = webRoots.get(relativePath);
if (paths == null) {
paths = new LinkedHashSet<String>();
webRoots.put(relativePath, paths);
}
paths.add(path);
private static void addPath(List<WebConfiguration.WebResource> webResources, String warRelativePath, String fileRelativePath, File file) {
warRelativePath = warRelativePath == null ? "" : warRelativePath;
WebConfiguration.WebResource webResource = new WebResourceImpl(warRelativePath, fileRelativePath, file);
webResources.add(webResource);
}
}
@@ -15,13 +15,11 @@
*/
package org.jetbrains.plugins.gradle.model;
import org.gradle.tooling.model.DomainObjectSet;
import org.jetbrains.annotations.NotNull;
import java.io.File;
import java.io.Serializable;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
@@ -42,10 +40,22 @@ public interface WebConfiguration extends Serializable {
File getWebXml();
Map<String, Set<String>> getWebRoots();
List<WebResource> getWebResources();
Set<File> getClasspath();
String getManifestContent();
}
interface WebResource extends Serializable {
@NotNull
String getWarDirectory();
@NotNull
String getRelativePath();
@NotNull
File getFile();
}
}
@@ -0,0 +1,96 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.plugins.gradle.tooling.internal;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.plugins.gradle.model.WebConfiguration;
import java.io.File;
import java.util.List;
import java.util.Set;
/**
* @author Vladislav.Soroka
* @since 2/10/14
*/
public class WarModelImpl implements WebConfiguration.WarModel {
@NotNull
private final String warName;
private final String myWebAppDirName;
private final File myWebAppDir;
private File myWebXml;
private List<WebConfiguration.WebResource> myWebResources;
private Set<File> myClasspath;
private String myManifestContent;
public WarModelImpl(@NotNull String name, String webAppDirName, File webAppDir) {
warName = name;
myWebAppDirName = webAppDirName;
myWebAppDir = webAppDir;
}
@NotNull
@Override
public String getWarName() {
return warName;
}
@Override
public String getWebAppDirName() {
return myWebAppDirName;
}
@Override
public File getWebAppDir() {
return myWebAppDir;
}
public void setWebXml(File webXml) {
myWebXml = webXml;
}
@Override
public File getWebXml() {
return myWebXml;
}
@Override
public List<WebConfiguration.WebResource> getWebResources() {
return myWebResources;
}
public void setWebResources(List<WebConfiguration.WebResource> webResources) {
myWebResources = webResources;
}
public void setClasspath(Set<File> classpath) {
myClasspath = classpath;
}
@Override
public Set<File> getClasspath() {
return myClasspath;
}
public void setManifestContent(String manifestContent) {
myManifestContent = manifestContent;
}
@Override
public String getManifestContent() {
return myManifestContent;
}
}
@@ -20,7 +20,6 @@ import org.jetbrains.plugins.gradle.model.WebConfiguration;
import java.io.File;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
@@ -40,73 +39,4 @@ public class WebConfigurationImpl implements WebConfiguration {
public List<? extends WarModel> getWarModels() {
return myWarModels;
}
public static class WarModelImpl implements WarModel {
@NotNull
private final String warName;
private final String myWebAppDirName;
private final File myWebAppDir;
private File myWebXml;
private Map<String, Set<String>> myWebRoots;
private Set<File> myClasspath;
private String myManifestContent;
public WarModelImpl(@NotNull String name, String webAppDirName, File webAppDir) {
warName = name;
myWebAppDirName = webAppDirName;
myWebAppDir = webAppDir;
}
@NotNull
@Override
public String getWarName() {
return warName;
}
@Override
public String getWebAppDirName() {
return myWebAppDirName;
}
@Override
public File getWebAppDir() {
return myWebAppDir;
}
public void setWebXml(File webXml) {
myWebXml = webXml;
}
@Override
public File getWebXml() {
return myWebXml;
}
@Override
public Map<String, Set<String>> getWebRoots() {
return myWebRoots;
}
public void setWebRoots(Map<String, Set<String>> webRoots) {
myWebRoots = webRoots;
}
public void setClasspath(Set<File> classpath) {
myClasspath = classpath;
}
@Override
public Set<File> getClasspath() {
return myClasspath;
}
public void setManifestContent(String manifestContent) {
myManifestContent = manifestContent;
}
@Override
public String getManifestContent() {
return myManifestContent;
}
}
}
@@ -0,0 +1,88 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.plugins.gradle.tooling.internal;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.plugins.gradle.model.WebConfiguration;
import java.io.File;
/**
* @author Vladislav.Soroka
* @since 2/10/14
*/
public class WebResourceImpl implements WebConfiguration.WebResource {
@NotNull
private final String myWarDirectory;
@NotNull
private final String myRelativePath;
@NotNull
private final File file;
public WebResourceImpl(@NotNull String warDirectory, @NotNull String relativePath, @NotNull File file) {
myWarDirectory = warDirectory;
this.myRelativePath = relativePath;
this.file = file;
}
@NotNull
@Override
public String getWarDirectory() {
return myWarDirectory;
}
@NotNull
@Override
public String getRelativePath() {
return myRelativePath;
}
@NotNull
@Override
public File getFile() {
return file;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof WebResourceImpl)) return false;
WebResourceImpl resource = (WebResourceImpl)o;
if (!file.getPath().equals(resource.file.getPath())) return false;
if (myWarDirectory != resource.myWarDirectory) return false;
if (!myRelativePath.equals(resource.myRelativePath)) return false;
return true;
}
@Override
public int hashCode() {
int result = myWarDirectory.hashCode();
result = 31 * result + myRelativePath.hashCode();
result = 31 * result + file.getPath().hashCode();
return result;
}
@Override
public String toString() {
return "WebResourceImpl{" +
"myWarDirectory=" + myWarDirectory +
", warRelativePath='" + myRelativePath + '\'' +
", file=" + file +
'}';
}
}