-
Notifications
You must be signed in to change notification settings - Fork 194
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Backport #406 Resolve DS classpath entry and generate component xmls
- Loading branch information
Showing
21 changed files
with
585 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
...java/org/eclipse/tycho/artifacts/configuration/DeclarativeServiceConfigurationReader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2022 Christoph Läubrich and others. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Contributors: | ||
* Christoph Läubrich - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.tycho.artifacts.configuration; | ||
|
||
import java.io.File; | ||
import java.io.FileInputStream; | ||
import java.io.FileNotFoundException; | ||
import java.io.IOException; | ||
import java.util.Properties; | ||
|
||
import org.apache.maven.model.Plugin; | ||
import org.apache.maven.project.MavenProject; | ||
import org.codehaus.plexus.component.annotations.Component; | ||
import org.codehaus.plexus.component.annotations.Requirement; | ||
import org.codehaus.plexus.logging.Logger; | ||
import org.codehaus.plexus.util.xml.Xpp3Dom; | ||
import org.eclipse.tycho.core.DeclarativeServicesConfiguration; | ||
import org.osgi.framework.Version; | ||
|
||
@Component(role = DeclarativeServiceConfigurationReader.class) | ||
public class DeclarativeServiceConfigurationReader { | ||
|
||
public static final String DEFAULT_ADD_TO_CLASSPATH = "true"; | ||
public static final String DEFAULT_DS_VERSION = "1.3"; | ||
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 PDE_DS_ANNOTATIONS_PREFS = ".settings/org.eclipse.pde.ds.annotations.prefs"; | ||
|
||
@Requirement | ||
private Logger logger; | ||
|
||
public DeclarativeServicesConfiguration getConfiguration(MavenProject mavenProject) throws IOException { | ||
Properties settings = getProjectSettings(mavenProject.getBasedir(), getMojoSettings(mavenProject, logger), | ||
mavenProject, logger); | ||
if (Boolean.parseBoolean(settings.getProperty(PROPERTY_ENABLED))) { | ||
return new DeclarativeServicesConfiguration() { | ||
|
||
@Override | ||
public boolean isAddToClasspath() { | ||
return Boolean.parseBoolean(settings.getProperty(PROPERTY_CLASSPATH, DEFAULT_ADD_TO_CLASSPATH)); | ||
} | ||
|
||
@Override | ||
public Version getSpecificationVersion() { | ||
String property = settings.getProperty(PROPERTY_DS_VERSION, DEFAULT_DS_VERSION); | ||
if (property.startsWith("V")) { | ||
property = property.substring(1).replace('_', '.'); | ||
} | ||
return Version.parseVersion(property); | ||
} | ||
}; | ||
} | ||
return null; | ||
} | ||
|
||
private static Properties getProjectSettings(File basedir, Properties mojoProperties, MavenProject mavenProject, | ||
Logger logger) throws FileNotFoundException, IOException { | ||
Properties properties = new Properties(mojoProperties); | ||
File prefs = new File(basedir, PDE_DS_ANNOTATIONS_PREFS); | ||
if (prefs.exists()) { | ||
try (FileInputStream stream = new FileInputStream(prefs)) { | ||
properties.load(stream); | ||
logger.debug("declarative-services project configuration for " + mavenProject.toString() + ":" | ||
+ System.lineSeparator() + 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"); | ||
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)); | ||
} | ||
} | ||
return properties; | ||
} | ||
|
||
private static void setProperty(Properties properties, String key, String attribute) { | ||
if (attribute != null && !attribute.isEmpty()) { | ||
properties.setProperty(key, attribute); | ||
} | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
tycho-core/src/main/java/org/eclipse/tycho/core/DeclarativeServicesConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2022 Christoph Läubrich and others. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Contributors: | ||
* Christoph Läubrich - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.tycho.core; | ||
|
||
import org.osgi.framework.Version; | ||
|
||
public interface DeclarativeServicesConfiguration { | ||
|
||
/** | ||
* Controls if the DS components annotations are made available on the compile-classpath, this | ||
* means no explicit import is required. | ||
*/ | ||
boolean isAddToClasspath(); | ||
|
||
/** | ||
* Controls the declarative services specification version to use. | ||
*/ | ||
Version getSpecificationVersion(); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>org.eclipse.tycho</groupId> | ||
<artifactId>tycho</artifactId> | ||
<version>2.7.2-SNAPSHOT</version> | ||
</parent> | ||
<artifactId>tycho-ds-plugin</artifactId> | ||
<packaging>maven-plugin</packaging> | ||
|
||
<name>Tycho OSGi Declarative Services Plugin</name> | ||
<description>A plugin for handling OSGi Declarative Services</description> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.apache.maven</groupId> | ||
<artifactId>maven-compat</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.maven</groupId> | ||
<artifactId>maven-plugin-api</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.maven.plugin-tools</groupId> | ||
<artifactId>maven-plugin-annotations</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.codehaus.plexus</groupId> | ||
<artifactId>plexus-utils</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.eclipse.tycho</groupId> | ||
<artifactId>tycho-core</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>biz.aQute.bnd</groupId> | ||
<artifactId>biz.aQute.bndlib</artifactId> | ||
<version>6.2.0</version> | ||
</dependency> | ||
</dependencies> | ||
</project> |
Oops, something went wrong.