Skip to content

Commit

Permalink
embedded-repo: Avoid multiple copies of the embedded repo
Browse files Browse the repository at this point in the history
The embedded-repo.jar is now ~5.8 MB in size. We had many copies of it.
Most of the maven plugins held a copy, the gradle plugin held a copy and
we had a special fragment which held a copy for Bndtools in Eclipse.

To avoid all these copies, we modify biz.aQute.bnd.embedded-repo to be
useable in Eclipse, replacing org.bndtools.embeddedrepo, as well as to
be useable as a dependency for the maven and gradle plugins.

This change also allowed the removal of special case code in
Workspace.CachedFileRepo to handle running in junit mode.

Of course, bnd.jar will still contain its own copy of embedded-repo.jar
since it must run as a standalone jar. But all other users now share the
copy in biz.aQute.bnd.embedded-repo.jar.

Signed-off-by: BJ Hargrave <[email protected]>
  • Loading branch information
bjhargrave committed Sep 23, 2019
1 parent 1b0875d commit dffa2aa
Show file tree
Hide file tree
Showing 25 changed files with 75 additions and 838 deletions.
20 changes: 10 additions & 10 deletions biz.aQute.bnd.embedded-repo/bnd.bnd
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@

-resourceonly: true

Fragment-Host: biz.aQute.bndlib;bundle-version="${range;[===,=+0);${base.version}}"

Bundle-Description: Embedded Repo for bnd workspace.
Timestamp: ${_@tstamp}

-includeresource: \
biz.aQute.launcher/biz.aQute.launcher-${base.version}.jar=${repo;biz.aQute.launcher;snapshot}, \
biz.aQute.launcher=@${repo;biz.aQute.launcher;snapshot}!/biz.aQute.launcher.pre.jar, \
biz.aQute.remote.launcher/biz.aQute.remote.launcher-${base.version}.jar=${repo;biz.aQute.remote.launcher;snapshot}, \
biz.aQute.junit/biz.aQute.junit-${base.version}.jar=${repo;biz.aQute.junit;snapshot}, \
biz.aQute.tester/biz.aQute.tester-${base.version}.jar=${repo;biz.aQute.tester;snapshot}
-buildpath: aQute.libg;version=project,\
biz.aQute.bndlib;version=latest;maven-optional=true

-includeresource: \
embedded-repo.jar

-dependson: \
biz.aQute.junit, \
biz.aQute.launcher, \
biz.aQute.remote, \
biz.aQute.tester

-digests: MD5, SHA1

-releaserepo:
Import-Package: \
javax.management,\
javax.management.openmbean,\
javax.management.remote
12 changes: 12 additions & 0 deletions biz.aQute.bnd.embedded-repo/bnd/embedded-repo.bnd
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Timestamp: ${_@tstamp}

-includeresource: \
biz.aQute.launcher/biz.aQute.launcher-${base.version}.jar=${repo;biz.aQute.launcher;snapshot}, \
biz.aQute.launcher=@${repo;biz.aQute.launcher;snapshot}!/biz.aQute.launcher.pre.jar, \
biz.aQute.remote.launcher/biz.aQute.remote.launcher-${base.version}.jar=${repo;biz.aQute.remote.launcher;snapshot}, \
biz.aQute.junit/biz.aQute.junit-${base.version}.jar=${repo;biz.aQute.junit;snapshot}, \
biz.aQute.tester/biz.aQute.tester-${base.version}.jar=${repo;biz.aQute.tester;snapshot}

-digests: MD5, SHA1

-pom: false
8 changes: 3 additions & 5 deletions biz.aQute.bnd.gradle/bnd.bnd
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
# for the bnd_version for the test cases.
-include: ${workspace}/cnf/includes/jdt.bnd, ${workspace}/gradle.properties

-dependson: biz.aQute.bnd.embedded-repo

-includepackage: \
aQute.bnd.gradle.*

Expand All @@ -20,14 +18,14 @@ Bundle-Description: The Bnd Gradle plugin.
aQute.libg;version=project, \
biz.aQute.bndlib;version=latest, \
biz.aQute.resolve;version=latest, \
biz.aQute.repository;version=latest
biz.aQute.repository;version=latest, \
biz.aQute.bnd.embedded-repo;version=latest

bnd_version: ${replace;${bnd_plugin};.*:(.*);$1}

-includeresource: \
OSGI-OPT/src=src, \
resources, \
embedded-repo.jar=${repo;biz.aQute.bnd.embedded-repo;snapshot}
resources

-builderignore: testresources

Expand Down
2 changes: 1 addition & 1 deletion biz.aQute.bnd/bnd.bnd
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@

-includeresource: \
${workspace}/LICENSE, \
embedded-repo.jar=${repo;biz.aQute.bnd.embedded-repo;snapshot}, \
templates=templates, \
@${repo;biz.aQute.bndlib;latest}!/!META-INF/*, \
@${repo;biz.aQute.repository;latest}!/!META-INF/*, \
@${repo;biz.aQute.resolve;latest}!/!META-INF/*, \
@${repo;biz.aQute.bnd.embedded-repo;latest}!/!META-INF/*, \
@${repo;biz.aQute.bnd.exporters;latest}!/!META-INF/*, \
@${repo;biz.aQute.bnd.reporter;latest}!/!META-INF/*, \
@${repo;biz.aQute.launchpad;latest}!/!META-INF/*, \
Expand Down
1 change: 0 additions & 1 deletion biz.aQute.bndall.tests/bnd.bnd
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

-include: ${workspace}/cnf/includes/jdt.bnd

-dependson: biz.aQute.bnd.embedded-repo
-nobundles: true

-testpath: \
Expand Down
62 changes: 23 additions & 39 deletions biz.aQute.bndlib/src/aQute/bnd/build/Workspace.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import java.net.URLClassLoader;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.attribute.FileTime;
import java.util.ArrayList;
import java.util.Collection;
Expand All @@ -28,7 +27,6 @@
import java.util.Map.Entry;
import java.util.Set;
import java.util.SortedSet;
import java.util.StringTokenizer;
import java.util.concurrent.Callable;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
Expand All @@ -44,8 +42,6 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.naming.TimeLimitExceededException;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -61,6 +57,7 @@
import aQute.bnd.osgi.Constants;
import aQute.bnd.osgi.Macro;
import aQute.bnd.osgi.Processor;
import aQute.bnd.osgi.Resource;
import aQute.bnd.osgi.Verifier;
import aQute.bnd.remoteworkspace.server.RemoteWorkspaceServer;
import aQute.bnd.resource.repository.ResourceRepositoryImpl;
Expand Down Expand Up @@ -102,8 +99,6 @@ public class Workspace extends Processor {

static final int BUFFER_SIZE = IOConstants.PAGE_SIZE * 16;
private static final String PLUGIN_STANDALONE = "-plugin.standalone_";
final static Pattern EMBEDDED_REPO_TESTING_PATTERN = Pattern
.compile(".*biz\\.aQute\\.bnd\\.embedded-repo(-.*)?\\.jar");

static class WorkspaceData {
List<RepositoryPlugin> repositories;
Expand Down Expand Up @@ -473,43 +468,32 @@ class CachedFileRepo extends FileRepo {

@Override
protected boolean init() throws Exception {
if (lock.tryLock(50, TimeUnit.SECONDS) == false)
throw new TimeLimitExceededException("Cached File Repo is locked and can't acquire it");
try {
if (super.init()) {
inited = true;
IO.mkdirs(root);
if (!root.isDirectory())
throw new IllegalArgumentException("Cache directory " + root + " not a directory");

try (InputStream in = getClass().getResourceAsStream(EMBEDDED_REPO)) {
if (in != null) {
unzip(in, root.toPath());
return true;
}
}
// We may be in unit test, look for
// biz.aQute.bnd.embedded-repo.jar on the
// classpath
StringTokenizer classPathTokenizer = new StringTokenizer(System.getProperty("java.class.path", ""),
File.pathSeparator);
while (classPathTokenizer.hasMoreTokens()) {
String classPathEntry = classPathTokenizer.nextToken()
.trim();
if (EMBEDDED_REPO_TESTING_PATTERN.matcher(classPathEntry)
.matches()) {
try (InputStream in = IO.stream(Paths.get(classPathEntry))) {
unzip(in, root.toPath());
return true;
if (lock.tryLock(50, TimeUnit.SECONDS)) {
try {
if (super.init()) {
inited = true;
IO.mkdirs(root);
if (!root.isDirectory())
throw new IllegalArgumentException("Cache directory " + root + " not a directory");

URL url = getClass().getResource(EMBEDDED_REPO);
if (url != null) {
try (Resource resource = Resource.fromURL(url);
InputStream in = resource.openInputStream()) {
if (in != null) {
unzip(in, root.toPath());
return true;
}
}
}
error("Could not find " + EMBEDDED_REPO + " as a resource on the classpath");
}
error("Couldn't find biz.aQute.bnd.embedded-repo on the classpath");
return false;
} else
return false;
} finally {
lock.unlock();
} finally {
lock.unlock();
}
} else {
throw new TimeoutException("Cannot acquire Cached File Repo lock");
}
}

Expand Down
2 changes: 1 addition & 1 deletion bndtools.core/bndtools.shared.bndrun
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ workspace.bundles: \
bndtools.pde;version=snapshot,\
bndtools.release;version=snapshot,\
org.bndtools.applaunch;version=snapshot,\
org.bndtools.embeddedrepo;version=snapshot,\
biz.aQute.bnd.embedded-repo;version=snapshot,\
org.bndtools.headless.build.manager;version=snapshot,\
org.bndtools.headless.build.plugin.ant;version=snapshot,\
org.bndtools.headless.build.plugin.gradle;version=snapshot,\
Expand Down
2 changes: 1 addition & 1 deletion dist/bnd.bnd
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
biz.aQute.bnd.exporters, \
biz.aQute.bnd.reporter, \
biz.aQute.bnd.runtime, \
biz.aQute.bnd.embedded-repo, \
biz.aQute.bnd.gradle, \
biz.aQute.bndlib, \
biz.aQute.bndlib.tests, \
Expand All @@ -31,7 +32,6 @@
bndtools.m2e, \
bndtools.pde, \
bndtools.release, \
org.bndtools.embeddedrepo, \
org.bndtools.headless.build.manager, \
org.bndtools.headless.build.plugin.ant, \
org.bndtools.headless.build.plugin.gradle, \
Expand Down
21 changes: 4 additions & 17 deletions maven/bnd-export-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,27 +52,14 @@
<groupId>biz.aQute.bnd</groupId>
<artifactId>biz.aQute.repository</artifactId>
</dependency>
<dependency>
<groupId>biz.aQute.bnd</groupId>
<artifactId>biz.aQute.bnd.embedded-repo</artifactId>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<configuration>
<artifactItems>
<artifactItem>
<groupId>biz.aQute.bnd</groupId>
<artifactId>biz.aQute.bnd.embedded-repo</artifactId>
<version>${project.version}</version>
<type>jar</type>
<overWrite>false</overWrite>
<outputDirectory>${project.build.outputDirectory}</outputDirectory>
<destFileName>embedded-repo.jar</destFileName>
</artifactItem>
</artifactItems>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-invoker-plugin</artifactId>
Expand Down
21 changes: 4 additions & 17 deletions maven/bnd-resolver-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,27 +52,14 @@
<groupId>biz.aQute.bnd</groupId>
<artifactId>biz.aQute.repository</artifactId>
</dependency>
<dependency>
<groupId>biz.aQute.bnd</groupId>
<artifactId>biz.aQute.bnd.embedded-repo</artifactId>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<configuration>
<artifactItems>
<artifactItem>
<groupId>biz.aQute.bnd</groupId>
<artifactId>biz.aQute.bnd.embedded-repo</artifactId>
<version>${project.version}</version>
<type>jar</type>
<overWrite>false</overWrite>
<outputDirectory>${project.build.outputDirectory}</outputDirectory>
<destFileName>embedded-repo.jar</destFileName>
</artifactItem>
</artifactItems>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-invoker-plugin</artifactId>
Expand Down
21 changes: 4 additions & 17 deletions maven/bnd-run-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,27 +52,14 @@
<groupId>biz.aQute.bnd</groupId>
<artifactId>biz.aQute.repository</artifactId>
</dependency>
<dependency>
<groupId>biz.aQute.bnd</groupId>
<artifactId>biz.aQute.bnd.embedded-repo</artifactId>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<configuration>
<artifactItems>
<artifactItem>
<groupId>biz.aQute.bnd</groupId>
<artifactId>biz.aQute.bnd.embedded-repo</artifactId>
<version>${project.version}</version>
<type>jar</type>
<overWrite>false</overWrite>
<outputDirectory>${project.build.outputDirectory}</outputDirectory>
<destFileName>embedded-repo.jar</destFileName>
</artifactItem>
</artifactItems>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-invoker-plugin</artifactId>
Expand Down
21 changes: 4 additions & 17 deletions maven/bnd-testing-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,27 +52,14 @@
<groupId>biz.aQute.bnd</groupId>
<artifactId>biz.aQute.repository</artifactId>
</dependency>
<dependency>
<groupId>biz.aQute.bnd</groupId>
<artifactId>biz.aQute.bnd.embedded-repo</artifactId>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<configuration>
<artifactItems>
<artifactItem>
<groupId>biz.aQute.bnd</groupId>
<artifactId>biz.aQute.bnd.embedded-repo</artifactId>
<version>${project.version}</version>
<type>jar</type>
<overWrite>false</overWrite>
<outputDirectory>${project.build.outputDirectory}</outputDirectory>
<destFileName>embedded-repo.jar</destFileName>
</artifactItem>
</artifactItems>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-invoker-plugin</artifactId>
Expand Down
5 changes: 5 additions & 0 deletions maven/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,11 @@
<artifactId>biz.aQute.bnd.reporter</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>biz.aQute.bnd</groupId>
<artifactId>biz.aQute.bnd.embedded-repo</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand Down
12 changes: 0 additions & 12 deletions org.bndtools.embeddedrepo/.classpath

This file was deleted.

3 changes: 0 additions & 3 deletions org.bndtools.embeddedrepo/.gitignore

This file was deleted.

Loading

0 comments on commit dffa2aa

Please sign in to comment.