This is an automated email from the ASF dual-hosted git repository. rombert pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-tooling-support-source.git
commit e05520ce515c8a98bc3ca548de6ee479685c4bbc Author: Carsten Ziegeler <[email protected]> AuthorDate: Wed Oct 4 14:45:44 2017 +0000 Move to latest parent pom and official OSGi annotations git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1811079 13f79535-47bb-0310-9956-ffa450edef68 --- pom.xml | 27 ++------ .../source/impl/SourceReferencesServlet.java | 72 +++++++++++----------- 2 files changed, 42 insertions(+), 57 deletions(-) diff --git a/pom.xml b/pom.xml index a9a72e3..972f6d0 100644 --- a/pom.xml +++ b/pom.xml @@ -23,7 +23,7 @@ <parent> <groupId>org.apache.sling</groupId> <artifactId>sling</artifactId> - <version>26</version> + <version>32</version> </parent> <artifactId>org.apache.sling.tooling.support.source</artifactId> @@ -42,10 +42,6 @@ <plugins> <plugin> <groupId>org.apache.felix</groupId> - <artifactId>maven-scr-plugin</artifactId> - </plugin> - <plugin> - <groupId>org.apache.felix</groupId> <artifactId>maven-bundle-plugin</artifactId> <extensions>true</extensions> <configuration> @@ -61,38 +57,27 @@ <dependencies> <dependency> + <groupId>org.osgi</groupId> + <artifactId>osgi.core</artifactId> + </dependency> + <dependency> <groupId>org.apache.felix</groupId> <artifactId>org.apache.felix.utils</artifactId> <version>1.9.0</version> <scope>provided</scope> </dependency> <dependency> - <groupId>org.apache.felix</groupId> - <artifactId>org.apache.felix.scr.annotations</artifactId> - </dependency> - <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> </dependency> <dependency> <groupId>javax.servlet</groupId> - <artifactId>servlet-api</artifactId> + <artifactId>javax.servlet-api</artifactId> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> </dependency> - <!-- override version to OSGi 4.3.0 to support BundleRevision --> - <dependency> - <groupId>org.osgi</groupId> - <artifactId>org.osgi.core</artifactId> - <!-- use the Java 7 compliant dependency: http://blog.osgi.org/2012/10/43-companion-code-for-java-7.html --> - <version>4.3.1</version> - </dependency> - <dependency> - <groupId>org.osgi</groupId> - <artifactId>org.osgi.compendium</artifactId> - </dependency> <dependency> <groupId>commons-io</groupId> <artifactId>commons-io</artifactId> diff --git a/src/main/java/org/apache/sling/tooling/support/source/impl/SourceReferencesServlet.java b/src/main/java/org/apache/sling/tooling/support/source/impl/SourceReferencesServlet.java index a2c6454..bf9d570 100644 --- a/src/main/java/org/apache/sling/tooling/support/source/impl/SourceReferencesServlet.java +++ b/src/main/java/org/apache/sling/tooling/support/source/impl/SourceReferencesServlet.java @@ -34,29 +34,29 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.commons.io.IOUtils; -import org.apache.felix.scr.annotations.Component; -import org.apache.felix.scr.annotations.Property; -import org.apache.felix.scr.annotations.Service; import org.apache.felix.utils.json.JSONWriter; import org.osgi.framework.Bundle; import org.osgi.framework.Constants; import org.osgi.framework.wiring.BundleRevision; import org.osgi.service.component.ComponentContext; +import org.osgi.service.component.annotations.Component; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * The <tt>SourceReferencesServlet</tt> infers and outputs source information about bundles running a Sling instance */ -@Component -@Service(value = Servlet.class) -@Property(name="alias", value="/system/sling/tooling/sourceReferences.json") +@Component(service = Servlet.class, + property = { + Constants.SERVICE_VENDOR + "=The Apache Software Foundation", + "alias=/system/sling/tooling/sourceReferences.json" + }) public class SourceReferencesServlet extends HttpServlet { private static final long serialVersionUID = 1L; - + private final Logger log = LoggerFactory.getLogger(getClass()); - + private static final String KEY_TYPE = "__type__"; private static final String KEY_GROUP_ID = "groupId"; private static final String KEY_ARTIFACT_ID = "artifactId"; @@ -72,19 +72,19 @@ public class SourceReferencesServlet extends HttpServlet { protected void activate(ComponentContext ctx) { this.ctx = ctx; - - finders = new ArrayList<SourceReferenceFinder>(); + + finders = new ArrayList<>(); finders.add(new FelixJettySourceReferenceFinder()); - } - + } + @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try { response.setContentType("application/json"); - + final JSONWriter w = new JSONWriter(response.getWriter()); w.array(); - + for ( Bundle bundle : ctx.getBundleContext().getBundles() ) { // skip bundle if it is a fragment (http://stackoverflow.com/questions/11655295/using-the-osgi-api-how-do-i-find-out-if-a-given-bundle-is-a-fragment) @@ -94,13 +94,13 @@ public class SourceReferencesServlet extends HttpServlet { continue; } Object bundleVersion = bundle.getHeaders().get(Constants.BUNDLE_VERSION); - + w.object(); w.key(Constants.BUNDLE_SYMBOLICNAME); w.value(bundle.getSymbolicName()); w.key(Constants.BUNDLE_VERSION); w.value(bundleVersion); - + w.key("sourceReferences"); w.array(); @@ -109,10 +109,10 @@ public class SourceReferencesServlet extends HttpServlet { if ( bundle.getBundleId() == 0 && bundle.getSymbolicName().equals(FELIX_FW_ARTIFACT_ID) ) { writeMavenGav(w, FELIX_FW_GROUP_ID, FELIX_FW_ARTIFACT_ID, (String) bundleVersion); } - + // look for pom.properties in the bundle ( the original bundle, fragments ) collectMavenSourceReferences(w, bundle); - + // look for pom.properties in jars embedded in the bundle for ( String jar : getEmbeddedJars(bundle)) { URL entry = bundle.getEntry(jar); @@ -122,7 +122,7 @@ public class SourceReferencesServlet extends HttpServlet { } collectMavenSourceRerefences(w, entry); } - + // query custom finders for source references for ( SourceReferenceFinder finder : finders ) { try { @@ -134,11 +134,11 @@ public class SourceReferencesServlet extends HttpServlet { log.warn(finder + " execution did not complete normally for " + bundle, e); } } - + w.endArray(); w.endObject(); } - + w.endArray(); } catch (IOException e) { throw new ServletException(e); @@ -146,12 +146,12 @@ public class SourceReferencesServlet extends HttpServlet { } private void collectMavenSourceReferences(JSONWriter w, Bundle bundle) throws IOException { - + Enumeration<?> entries = bundle.findEntries("/META-INF/maven", "pom.properties", true); - + while ( entries != null && entries.hasMoreElements()) { URL entry = (URL) entries.nextElement(); - + InputStream in = entry.openStream(); try { writeMavenGav(w, in); @@ -160,9 +160,9 @@ public class SourceReferencesServlet extends HttpServlet { } } } - + private void writeMavenGav(JSONWriter w, String groupId, String artifactId, String version) throws IOException { - + w.object(); w.key(KEY_TYPE).value(VALUE_TYPE_MAVEN); w.key(KEY_GROUP_ID).value(groupId); @@ -170,9 +170,9 @@ public class SourceReferencesServlet extends HttpServlet { w.key(KEY_VERSION).value(version); w.endObject(); } - + private void writeMavenGav(JSONWriter w, InputStream in) throws IOException { - + Properties p = new Properties(); p.load(in); w.object(); @@ -182,28 +182,28 @@ public class SourceReferencesServlet extends HttpServlet { } w.endObject(); } - + private List<String> getEmbeddedJars(Bundle bundle) { - + String classPath = (String) bundle.getHeaders().get(Constants.BUNDLE_CLASSPATH); if ( classPath == null ) { return Collections.emptyList(); } - List<String> embeddedJars = new ArrayList<String>(); - + List<String> embeddedJars = new ArrayList<>(); + String[] classPathEntryNames = classPath.split("\\,"); for ( String classPathEntry : classPathEntryNames ) { if ( classPathEntry.endsWith(".jar")) { embeddedJars.add(classPathEntry); } } - + return embeddedJars; } - + private void collectMavenSourceRerefences(JSONWriter w, URL entry) throws IOException { - + InputStream wrappedIn = entry.openStream(); try { JarInputStream jarIs = new JarInputStream(wrappedIn); @@ -217,6 +217,6 @@ public class SourceReferencesServlet extends HttpServlet { } finally { IOUtils.closeQuietly(wrappedIn); } - } + } } -- To stop receiving notification emails like this one, please contact "[email protected]" <[email protected]>.
