mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Support 'overwrite' parameter for maven-resources-plugin.
This commit is contained in:
+13
-7
@@ -64,16 +64,22 @@ public class MavenResourcesBuilder extends TargetBuilder<MavenResourceRootDescri
|
||||
Arrays.sort(roots, new Comparator<MavenResourceRootDescriptor>() {
|
||||
@Override
|
||||
public int compare(MavenResourceRootDescriptor r1, MavenResourceRootDescriptor r2) {
|
||||
if (r1.getConfiguration().isFiltered) {
|
||||
if (!r2.getConfiguration().isFiltered) return 1;
|
||||
int res = r1.getIndexInPom() - r2.getIndexInPom();
|
||||
|
||||
return r1.getIndexInPom() - r2.getIndexInPom();
|
||||
}
|
||||
else {
|
||||
if (r2.getConfiguration().isFiltered) return -1;
|
||||
if (r1.isOverwrite()) {
|
||||
assert r2.isOverwrite(); // 'overwrite' parameters is common for all roots in module.
|
||||
|
||||
return r2.getIndexInPom() - r1.getIndexInPom();
|
||||
return res;
|
||||
}
|
||||
|
||||
if (r1.getConfiguration().isFiltered && !r2.getConfiguration().isFiltered) return 1;
|
||||
if (!r1.getConfiguration().isFiltered && r2.getConfiguration().isFiltered) return -1;
|
||||
|
||||
if (!r1.getConfiguration().isFiltered) {
|
||||
res = -res;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
+4
@@ -63,6 +63,9 @@ public class MavenModuleResourceConfiguration {
|
||||
@OptionTag
|
||||
public boolean escapeWindowsPaths = true;
|
||||
|
||||
@OptionTag
|
||||
public boolean overwrite;
|
||||
|
||||
@Tag("resources")
|
||||
@AbstractCollection(surroundWithTag = false, elementTag = "resource")
|
||||
public List<ResourceRootConfiguration> resources = new ArrayList<ResourceRootConfiguration>();
|
||||
@@ -102,6 +105,7 @@ public class MavenModuleResourceConfiguration {
|
||||
result = 31 * result + filteringExclusions.hashCode();
|
||||
result = 31 * result + (escapeString != null ? escapeString.hashCode() : 0);
|
||||
result = 31 * result + (escapeWindowsPaths ? 1 : 0);
|
||||
result = 31 * result + (overwrite ? 1 : 0);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
+10
-1
@@ -31,16 +31,21 @@ public class MavenResourceRootDescriptor extends BuildRootDescriptor {
|
||||
private final ResourceRootConfiguration myConfig;
|
||||
private final File myFile;
|
||||
private final String myId;
|
||||
private final boolean myOverwrite;
|
||||
|
||||
private final int myIndexInPom;
|
||||
|
||||
public MavenResourceRootDescriptor(@NotNull MavenResourcesTarget target, ResourceRootConfiguration config, int indexInPom) {
|
||||
public MavenResourceRootDescriptor(@NotNull MavenResourcesTarget target,
|
||||
ResourceRootConfiguration config,
|
||||
int indexInPom,
|
||||
boolean overwrite) {
|
||||
myTarget = target;
|
||||
myConfig = config;
|
||||
final String path = FileUtil.toCanonicalPath(config.directory);
|
||||
myFile = new File(path);
|
||||
myId = path;
|
||||
myIndexInPom = indexInPom;
|
||||
myOverwrite = overwrite;
|
||||
}
|
||||
|
||||
public ResourceRootConfiguration getConfiguration() {
|
||||
@@ -76,4 +81,8 @@ public class MavenResourceRootDescriptor extends BuildRootDescriptor {
|
||||
public int getIndexInPom() {
|
||||
return myIndexInPom;
|
||||
}
|
||||
|
||||
public boolean isOverwrite() {
|
||||
return myOverwrite;
|
||||
}
|
||||
}
|
||||
|
||||
+6
-2
@@ -66,10 +66,14 @@ public class MavenResourcesTarget extends ModuleBasedTarget<MavenResourceRootDes
|
||||
// todo: should we honor ignored and excluded roots here?
|
||||
final List<MavenResourceRootDescriptor> result = new ArrayList<MavenResourceRootDescriptor>();
|
||||
|
||||
MavenProjectConfiguration projectConfig = JpsMavenExtensionService.getInstance().getMavenProjectConfiguration(dataPaths);
|
||||
MavenModuleResourceConfiguration moduleConfig = projectConfig.moduleConfigurations.get(myModule.getName());
|
||||
if (moduleConfig == null) return Collections.emptyList();
|
||||
|
||||
int i = 0;
|
||||
|
||||
for (ResourceRootConfiguration resource : getRootConfigurations(dataPaths)) {
|
||||
result.add(new MavenResourceRootDescriptor(this, resource, i++));
|
||||
for (ResourceRootConfiguration resource : getRootConfigurations(moduleConfig)) {
|
||||
result.add(new MavenResourceRootDescriptor(this, resource, i++, moduleConfig.overwrite));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
+5
@@ -135,6 +135,11 @@ public class MavenResourceCompilerConfigurationGenerator {
|
||||
resourceConfig.escapeWindowsPaths = Boolean.parseBoolean(escapeWindowsPaths);
|
||||
}
|
||||
|
||||
String overwrite = MavenJDOMUtil.findChildValueByPath(pluginConfiguration, "overwrite");
|
||||
if (overwrite != null) {
|
||||
resourceConfig.overwrite = Boolean.parseBoolean(overwrite);
|
||||
}
|
||||
|
||||
projectConfig.moduleConfigurations.put(module.getName(), resourceConfig);
|
||||
}
|
||||
|
||||
|
||||
+73
@@ -1107,4 +1107,77 @@ public abstract class ResourceFilteringTest extends MavenCompilingTestCase {
|
||||
assertResult("target/classes/a.txt", "2"); // For the filtered files last file override other files.
|
||||
}
|
||||
|
||||
public void testOverwriteParameter1() throws Exception {
|
||||
if (!useJps()) return;
|
||||
|
||||
createProjectSubFile("resources1/a.txt", "1");
|
||||
createProjectSubFile("resources2/a.txt", "2");
|
||||
|
||||
importProject("<groupId>test</groupId>" +
|
||||
"<artifactId>project</artifactId>" +
|
||||
"<version>1</version>" +
|
||||
"" +
|
||||
|
||||
"<build>" +
|
||||
" <resources>" +
|
||||
" <resource>" +
|
||||
" <directory>resources1</directory>" +
|
||||
" </resource>" +
|
||||
" <resource>" +
|
||||
" <directory>resources2</directory>" +
|
||||
" </resource>" +
|
||||
" </resources>" +
|
||||
"" +
|
||||
" <plugins>" +
|
||||
" <plugin>" +
|
||||
" <artifactId>maven-resources-plugin</artifactId>" +
|
||||
" <configuration>" +
|
||||
" <overwrite>true</overwrite>" +
|
||||
" </configuration>" +
|
||||
" </plugin>" +
|
||||
" </plugins>" +
|
||||
"</build>");
|
||||
|
||||
compileModules("project");
|
||||
|
||||
assertResult("target/classes/a.txt", "2");
|
||||
}
|
||||
|
||||
public void testOverwriteParameter2() throws Exception {
|
||||
if (!useJps()) return;
|
||||
|
||||
createProjectSubFile("resources1/a.txt", "1");
|
||||
createProjectSubFile("resources2/a.txt", "2");
|
||||
|
||||
importProject("<groupId>test</groupId>" +
|
||||
"<artifactId>project</artifactId>" +
|
||||
"<version>1</version>" +
|
||||
"" +
|
||||
|
||||
"<build>" +
|
||||
" <resources>" +
|
||||
" <resource>" +
|
||||
" <directory>resources1</directory>" +
|
||||
" <filtering>true</filtering>" +
|
||||
" </resource>" +
|
||||
" <resource>" +
|
||||
" <directory>resources2</directory>" +
|
||||
" </resource>" +
|
||||
" </resources>" +
|
||||
"" +
|
||||
" <plugins>" +
|
||||
" <plugin>" +
|
||||
" <artifactId>maven-resources-plugin</artifactId>" +
|
||||
" <configuration>" +
|
||||
" <overwrite>true</overwrite>" +
|
||||
" </configuration>" +
|
||||
" </plugin>" +
|
||||
" </plugins>" +
|
||||
"</build>");
|
||||
|
||||
compileModules("project");
|
||||
|
||||
assertResult("target/classes/a.txt", "2");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user