diff --git a/tycho-core/src/main/java/org/eclipse/tycho/artifacts/configuration/DeclarativeServiceConfigurationReader.java b/tycho-core/src/main/java/org/eclipse/tycho/artifacts/configuration/DeclarativeServiceConfigurationReader.java index 6faa5aec18..daf3de9d5b 100644 --- a/tycho-core/src/main/java/org/eclipse/tycho/artifacts/configuration/DeclarativeServiceConfigurationReader.java +++ b/tycho-core/src/main/java/org/eclipse/tycho/artifacts/configuration/DeclarativeServiceConfigurationReader.java @@ -28,11 +28,14 @@ @Component(role = DeclarativeServiceConfigurationReader.class) public class DeclarativeServiceConfigurationReader { + private static final String DS_PLUGIN = "org.eclipse.tycho:tycho-ds-plugin"; public static final String DEFAULT_ADD_TO_CLASSPATH = "true"; public static final String DEFAULT_DS_VERSION = "1.3"; + public static final String DEFAULT_PATH = "OSGI-INF"; private static final String PROPERTY_CLASSPATH = "classpath"; private static final String PROPERTY_DS_VERSION = "dsVersion"; private static final String PROPERTY_ENABLED = "enabled"; + private static final String PROPERTY_PATH = "path"; private static final String PDE_DS_ANNOTATIONS_PREFS = ".settings/org.eclipse.pde.ds.annotations.prefs"; @@ -58,6 +61,11 @@ public Version getSpecificationVersion() { } return Version.parseVersion(property); } + + @Override + public String getPath() { + return settings.getProperty(PROPERTY_PATH, DEFAULT_PATH); + } }; } return null; @@ -74,12 +82,13 @@ private static Properties getProjectSettings(File basedir, Properties mojoProper + System.lineSeparator() + properties); } } + logger.debug("Project configuration for " + mavenProject + ": " + properties); return properties; } private static Properties getMojoSettings(MavenProject project, Logger logger) { Properties properties = new Properties(); - Plugin plugin = project.getPlugin("org.eclipse.tycho:tycho-ds-plugin"); + Plugin plugin = project.getPlugin(DS_PLUGIN); if (plugin != null) { Xpp3Dom configuration = (Xpp3Dom) plugin.getConfiguration(); if (configuration != null) { @@ -87,17 +96,26 @@ private static Properties getMojoSettings(MavenProject project, Logger logger) { logger.debug("declarative-services mojo configuration for " + project.toString() + ":" + System.lineSeparator() + configuration.toString()); } - setProperty(properties, PROPERTY_CLASSPATH, configuration.getAttribute(PROPERTY_CLASSPATH)); - setProperty(properties, PROPERTY_DS_VERSION, configuration.getAttribute(PROPERTY_DS_VERSION)); - setProperty(properties, PROPERTY_ENABLED, configuration.getAttribute(PROPERTY_ENABLED)); + setProperty(properties, PROPERTY_CLASSPATH, configuration.getChild(PROPERTY_CLASSPATH)); + setProperty(properties, PROPERTY_DS_VERSION, configuration.getChild(PROPERTY_DS_VERSION)); + setProperty(properties, PROPERTY_ENABLED, configuration.getChild(PROPERTY_ENABLED)); + setProperty(properties, PROPERTY_PATH, configuration.getChild(PROPERTY_PATH)); + logger.debug("Mojo configuration for " + project + ": " + properties); + } else { + logger.debug("DS Plugin " + DS_PLUGIN + " has no useable configuration."); } + } else { + logger.debug("DS Plugin " + DS_PLUGIN + " not found"); } return properties; } - private static void setProperty(Properties properties, String key, String attribute) { - if (attribute != null && !attribute.isEmpty()) { - properties.setProperty(key, attribute); + private static void setProperty(Properties properties, String key, Xpp3Dom xpp3Dom) { + if (xpp3Dom != null) { + String value = xpp3Dom.getValue(); + if (value != null && !value.isBlank()) { + properties.setProperty(key, value); + } } } } diff --git a/tycho-core/src/main/java/org/eclipse/tycho/core/DeclarativeServicesConfiguration.java b/tycho-core/src/main/java/org/eclipse/tycho/core/DeclarativeServicesConfiguration.java index 8b551ae9aa..b73791d2c2 100644 --- a/tycho-core/src/main/java/org/eclipse/tycho/core/DeclarativeServicesConfiguration.java +++ b/tycho-core/src/main/java/org/eclipse/tycho/core/DeclarativeServicesConfiguration.java @@ -25,4 +25,10 @@ public interface DeclarativeServicesConfiguration { */ Version getSpecificationVersion(); + /** + * + * @return the path where generated data should be placed + */ + String getPath(); + } diff --git a/tycho-ds-plugin/src/main/java/org/eclipse/tycho/ds/DeclarativeServicesMojo.java b/tycho-ds-plugin/src/main/java/org/eclipse/tycho/ds/DeclarativeServicesMojo.java index 4d86a30b6a..6a6a20ce3a 100644 --- a/tycho-ds-plugin/src/main/java/org/eclipse/tycho/ds/DeclarativeServicesMojo.java +++ b/tycho-ds-plugin/src/main/java/org/eclipse/tycho/ds/DeclarativeServicesMojo.java @@ -71,7 +71,7 @@ public class DeclarativeServicesMojo extends AbstractMojo { /** * The desired path where to place component definitions */ - @Parameter(property = "tycho.ds.path", defaultValue = "OSGI-INF") + @Parameter(property = "tycho.ds.path", defaultValue = DeclarativeServiceConfigurationReader.DEFAULT_PATH) private String path = "OSGI-INF"; @Parameter(property = "project", readonly = true) @@ -97,8 +97,9 @@ public void execute() throws MojoExecutionException, MojoFailureException { return; } File outputDirectory = new File(project.getBuild().getOutputDirectory()); - File targetDirectory = new File(outputDirectory, path); - File projectBaseDir = new File(project.getBasedir(), path); + String childPath = configuration.getPath(); + File targetDirectory = new File(outputDirectory, childPath); + File projectBaseDir = new File(project.getBasedir(), childPath); try (Jar mavenProjectJar = new Jar(project.getName(), outputDirectory, null); Analyzer analyzer = new Analyzer(mavenProjectJar)) { Map directory = analyzer.getJar().getDirectory("OSGI-INF");