Skip to content

Commit

Permalink
Fix Mojo Configuration of DS Plugin is ignored
Browse files Browse the repository at this point in the history
Currently the mojo config is assumed to be *attributes* of the
configuration element, but actually the are child *elements*

Also adding some more debug output in case something is ignored and user
wants to find out why
  • Loading branch information
laeubi committed Jun 27, 2022
1 parent 759933f commit d97a8af
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -58,6 +61,11 @@ public Version getSpecificationVersion() {
}
return Version.parseVersion(property);
}

@Override
public String getPath() {
return settings.getProperty(PROPERTY_PATH, DEFAULT_PATH);
}
};
}
return null;
Expand All @@ -74,30 +82,40 @@ 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) {
if (logger.isDebugEnabled()) {
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);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,10 @@ public interface DeclarativeServicesConfiguration {
*/
Version getSpecificationVersion();

/**
*
* @return the path where generated data should be placed
*/
String getPath();

}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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<String, Resource> directory = analyzer.getJar().getDirectory("OSGI-INF");
Expand Down

0 comments on commit d97a8af

Please sign in to comment.