mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Gradle: war facet web roots importing fixes -
IDEA-126544 Gradle WAR: Empty directories in 'war' are not included during import IDEA-126545 Gradle WAR: Resource directory in 'war' with 'into' closure not imported
This commit is contained in:
+2
-4
@@ -24,11 +24,11 @@ import com.intellij.util.Function;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.gradle.tooling.model.idea.IdeaModule;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.plugins.gradle.model.web.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.model.web.WebConfiguration;
|
||||
import org.jetbrains.plugins.gradle.service.project.AbstractProjectResolverExtension;
|
||||
import org.jetbrains.plugins.gradle.util.GradleConstants;
|
||||
|
||||
@@ -82,9 +82,7 @@ public class JavaEEGradleProjectResolverExtension extends AbstractProjectResolve
|
||||
public WebResource fun(WebConfiguration.WebResource resource) {
|
||||
if (resource == null) return null;
|
||||
|
||||
final WarDirectory warDirectory =
|
||||
WarDirectory.fromPath(resource.getWarDirectory());
|
||||
if (warDirectory == null) return null;
|
||||
final WarDirectory warDirectory = WarDirectory.fromPath(resource.getWarDirectory());
|
||||
return new WebResource(warDirectory, resource.getRelativePath(), resource.getFile());
|
||||
}
|
||||
});
|
||||
|
||||
@@ -17,44 +17,46 @@ 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 class 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("/"),
|
||||
public static final WarDirectory WAR_ROOT = new WarDirectory("/");
|
||||
/**
|
||||
* 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"),
|
||||
public static final WarDirectory META_INF = new WarDirectory("/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"),
|
||||
public static final WarDirectory WEB_INF = new WarDirectory("/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"),
|
||||
public static final WarDirectory WEB_INF_LIB = new WarDirectory("/WEB-INF/lib");
|
||||
/**
|
||||
* Subdirectory contains the compiled Java code for the Web module.
|
||||
*/
|
||||
WEB_INF_CLASSES("/WEB-INF/classes");
|
||||
public static final WarDirectory WEB_INF_CLASSES = new WarDirectory("/WEB-INF/classes");
|
||||
|
||||
private static final WarDirectory[] WAR_DIRECTORIES = new WarDirectory[]{WAR_ROOT, META_INF, WEB_INF, WEB_INF_LIB, WEB_INF_CLASSES};
|
||||
|
||||
@NotNull
|
||||
private final String myRelativePath;
|
||||
|
||||
WarDirectory(@NotNull final String relativePath) {
|
||||
myRelativePath = relativePath;
|
||||
myRelativePath = getAdjustedPath(relativePath);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -62,14 +64,44 @@ public enum WarDirectory {
|
||||
return myRelativePath;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public boolean isCustomDirectory() {
|
||||
for (WarDirectory warDirectory : WAR_DIRECTORIES) {
|
||||
if (myRelativePath.equals(warDirectory.getRelativePath())) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
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()) {
|
||||
final String adjustedPath = getAdjustedPath(path);
|
||||
for (WarDirectory warDirectory : WAR_DIRECTORIES) {
|
||||
if (warDirectory.myRelativePath.equals(adjustedPath)) return warDirectory;
|
||||
}
|
||||
return null;
|
||||
return new WarDirectory(adjustedPath);
|
||||
}
|
||||
|
||||
private static String getAdjustedPath(final @NotNull String path) {
|
||||
return path.isEmpty() || path.charAt(0) != '/' ? '/' + path : path;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return myRelativePath;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
WarDirectory directory = (WarDirectory)o;
|
||||
if (!myRelativePath.equals(directory.myRelativePath)) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return myRelativePath.hashCode();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ public class WebResource implements Serializable {
|
||||
|
||||
public WebResource(@NotNull WarDirectory warDirectory, @NotNull String warRelativePath, @NotNull File file) {
|
||||
myWarDirectory = warDirectory;
|
||||
this.warRelativePath = warRelativePath;
|
||||
this.warRelativePath = getAdjustedPath(warRelativePath);
|
||||
this.file = file;
|
||||
}
|
||||
|
||||
@@ -55,6 +55,10 @@ public class WebResource implements Serializable {
|
||||
return file;
|
||||
}
|
||||
|
||||
private static String getAdjustedPath(final @NotNull String path) {
|
||||
return path.isEmpty() || path.charAt(0) != '/' ? '/' + path : path;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
|
||||
+19
@@ -68,6 +68,7 @@ class WarModelBuilderImpl implements ModelBuilderService {
|
||||
final List<WebConfiguration.WebResource> webResources = []
|
||||
final War warTask = task as War
|
||||
warModel.webXml = warTask.webXml
|
||||
warTask.rootSpec.setIncludeEmptyDirs(true)
|
||||
|
||||
warTask.rootSpec.walk({ def resolver ->
|
||||
// def resolver ->
|
||||
@@ -83,6 +84,24 @@ class WarModelBuilderImpl implements ModelBuilderService {
|
||||
}
|
||||
|
||||
final String relativePath = resolver.destPath.pathString
|
||||
final def sourcePaths
|
||||
|
||||
if (resolver.metaClass.respondsTo(resolver, 'getSourcePaths')) {
|
||||
sourcePaths = resolver.getSourcePaths()
|
||||
} else if (resolver.this$0.metaClass.respondsTo(resolver, 'getSourcePaths')) {
|
||||
sourcePaths = resolver.this$0.getSourcePaths()
|
||||
} else {
|
||||
throw new RuntimeException("${GradleVersion.current()} is not supported by web artifact importer")
|
||||
}
|
||||
|
||||
(sourcePaths.flatten() as List).each { def path ->
|
||||
if (path instanceof String) {
|
||||
def file = new File(warTask.project.projectDir, path)
|
||||
addPath(webResources, relativePath, "", file)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
resolver.source.visit(new FileVisitor() {
|
||||
@Override
|
||||
public void visitDir(FileVisitDetails dirDetails) {
|
||||
|
||||
@@ -1,3 +1,42 @@
|
||||
//noinspection GrPackage
|
||||
|
||||
apply plugin: 'war'
|
||||
|
||||
configurations {
|
||||
moreLibs
|
||||
}
|
||||
|
||||
//repositories {
|
||||
// flatDir { dirs "lib" }
|
||||
// mavenCentral()
|
||||
//}
|
||||
//
|
||||
//dependencies {
|
||||
// compile module(":compile:1.0") {
|
||||
// dependency ":compile-transitive-1.0@jar"
|
||||
// dependency ":providedCompile-transitive:1.0@jar"
|
||||
// }
|
||||
// providedCompile "javax.servlet:servlet-api:2.5"
|
||||
// providedCompile module(":providedCompile:1.0") {
|
||||
// dependency ":providedCompile-transitive:1.0@jar"
|
||||
// }
|
||||
// runtime ":runtime:1.0"
|
||||
// providedRuntime ":providedRuntime:1.0@jar"
|
||||
// testCompile "junit:junit:4.11"
|
||||
// moreLibs ":otherLib:1.0"
|
||||
//
|
||||
// runtime files('extras')
|
||||
//}
|
||||
|
||||
|
||||
war {
|
||||
from('src/rootContent') {
|
||||
into 'bar'
|
||||
}
|
||||
webInf { from 'src/additionalWebInf' } // adds a file-set to the WEB-INF dir.
|
||||
exclude 'excl'
|
||||
classpath fileTree('additionalLibs') // adds a file-set to the WEB-INF/lib dir.
|
||||
classpath configurations.moreLibs // adds a configuration to the WEB-INF/lib dir.
|
||||
webXml = file('src/someWeb.xml') // copies a file to WEB-INF/web.xml
|
||||
classpath file('src/bbb')
|
||||
}
|
||||
+13
-1
@@ -26,6 +26,9 @@ import org.junit.Test;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.jetbrains.plugins.gradle.model.web.WebConfiguration.WarModel;
|
||||
import static org.jetbrains.plugins.gradle.model.web.WebConfiguration.WebResource;
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
@@ -53,8 +56,17 @@ public class WebConfigurationBuilderImplTest extends AbstractModelBuilderTest {
|
||||
WebConfiguration webConfiguration = ideaModule.get(0);
|
||||
assertEquals(1, webConfiguration.getWarModels().size());
|
||||
|
||||
final WebConfiguration.WarModel warModel = webConfiguration.getWarModels().iterator().next();
|
||||
final WarModel warModel = webConfiguration.getWarModels().iterator().next();
|
||||
assertEquals("src/main/webapp", warModel.getWebAppDirName());
|
||||
|
||||
assertArrayEquals(
|
||||
new String[]{"MANIFEST.MF", "additionalWebInf", "rootContent"},
|
||||
ContainerUtil.map2Array(warModel.getWebResources(), new Function<WebResource, Object>() {
|
||||
@Override
|
||||
public String fun(WebResource resource) {
|
||||
return resource.getFile().getName();
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user