From 2929e2d01e12af9141a61923f25cb95f580e49d4 Mon Sep 17 00:00:00 2001 From: Stuart McCulloch Date: Tue, 7 Aug 2012 10:57:21 +0000 Subject: [PATCH] Latest bnd sync git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1370165 13f79535-47bb-0310-9956-ffa450edef68 --- .../main/java/aQute/bnd/build/Container.java | 3 + .../main/java/aQute/bnd/build/Project.java | 79 +++---- .../java/aQute/bnd/build/ProjectBuilder.java | 4 + .../java/aQute/bnd/build/ProjectMessages.java | 3 +- .../java/aQute/bnd/build/ProjectTester.java | 4 +- .../java/aQute/bnd/build/ReflectAction.java | 1 + .../main/java/aQute/bnd/build/Workspace.java | 18 +- .../aQute/bnd/build/WorkspaceRepository.java | 2 +- .../src/main/java/aQute/bnd/build/packageinfo | 2 +- .../java/aQute/bnd/compatibility/Access.java | 1 + .../bnd/compatibility/GenericParameter.java | 1 + .../java/aQute/bnd/compatibility/Kind.java | 1 + .../java/aQute/bnd/compatibility/Scope.java | 1 + .../aQute/bnd/component/AnnotationReader.java | 1 + .../aQute/bnd/component/DSAnnotations.java | 16 +- .../aQute/bnd/component/HeaderReader.java | 1 + .../aQute/bnd/component/ReferenceDef.java | 1 + .../java/aQute/bnd/component/TagResource.java | 2 + .../main/java/aQute/bnd/differ/DiffImpl.java | 3 + .../main/java/aQute/bnd/differ/Element.java | 3 + .../java/aQute/bnd/filerepo/FileRepo.java | 7 +- .../src/main/java/aQute/bnd/header/Attrs.java | 4 +- .../java/aQute/bnd/header/Parameters.java | 3 + .../bnd/make/calltree/CalltreeResource.java | 3 + .../component/ComponentAnnotationReader.java | 1 + .../bnd/make/component/ServiceComponent.java | 2 - .../aQute/bnd/make/coverage/Coverage.java | 4 + .../bnd/make/metatype/MetaTypeReader.java | 2 + .../java/aQute/bnd/maven/MavenCommand.java | 16 +- .../aQute/bnd/maven/MavenDependencyGraph.java | 1 + .../java/aQute/bnd/maven/MavenDeploy.java | 88 ++++---- .../java/aQute/bnd/maven/MavenDeployCmd.java | 8 +- .../java/aQute/bnd/maven/MavenRepository.java | 3 +- .../aQute/bnd/maven/support/CachedPom.java | 1 + .../aQute/bnd/maven/support/MavenEntry.java | 8 +- .../maven/support/MavenRemoteRepository.java | 3 +- .../java/aQute/bnd/maven/support/Pom.java | 1 + .../aQute/bnd/maven/support/ProjectPom.java | 1 + .../java/aQute/bnd/maven/support/packageinfo | 2 +- .../main/java/aQute/bnd/osgi/Analyzer.java | 14 +- .../main/java/aQute/bnd/osgi/Annotation.java | 1 + .../src/main/java/aQute/bnd/osgi/Builder.java | 8 +- .../main/java/aQute/bnd/osgi/BundleId.java | 2 + .../src/main/java/aQute/bnd/osgi/Clazz.java | 12 +- .../java/aQute/bnd/osgi/CombinedResource.java | 1 + .../main/java/aQute/bnd/osgi/Descriptors.java | 10 + .../java/aQute/bnd/osgi/EmbeddedResource.java | 1 + .../java/aQute/bnd/osgi/FileResource.java | 1 + .../main/java/aQute/bnd/osgi/Instruction.java | 1 + .../java/aQute/bnd/osgi/Instructions.java | 1 + .../src/main/java/aQute/bnd/osgi/Jar.java | 10 +- .../main/java/aQute/bnd/osgi/JarResource.java | 3 + .../src/main/java/aQute/bnd/osgi/Macro.java | 1 + .../main/java/aQute/bnd/osgi/Packages.java | 3 + .../aQute/bnd/osgi/PreprocessResource.java | 1 + .../main/java/aQute/bnd/osgi/Processor.java | 25 ++- .../main/java/aQute/bnd/osgi/URLResource.java | 1 + .../main/java/aQute/bnd/osgi/Verifier.java | 2 + .../java/aQute/bnd/osgi/WriteResource.java | 1 + .../main/java/aQute/bnd/osgi/ZipResource.java | 1 + .../java/aQute/bnd/osgi/resource/Filters.java | 1 - .../aQute/bnd/repo/eclipse/EclipseRepo.java | 7 +- .../main/java/aQute/bnd/service/Deploy.java | 5 +- .../aQute/bnd/service/RepositoryPlugin.java | 102 ++++++++- .../main/java/aQute/bnd/service/packageinfo | 2 +- .../service/repository/MinimalRepository.java | 2 +- .../java/aQute/bnd/signing/JartoolSigner.java | 1 + .../main/java/aQute/bnd/version/Version.java | 3 + .../java/aQute/bnd/version/VersionRange.java | 1 + .../main/java/aQute/lib/base64/Base64.java | 1 + .../aQute/lib/collections/SortedList.java | 3 + .../aQute/lib/deployer/FileInstallRepo.java | 121 +++++++---- .../java/aQute/lib/deployer/FileRepo.java | 203 ++++++++++++++---- .../main/java/aQute/lib/filter/Filter.java | 4 + .../src/main/java/aQute/lib/index/Index.java | 2 + .../src/main/java/aQute/lib/io/IO.java | 4 +- .../java/aQute/lib/json/ByteArrayHandler.java | 3 +- .../src/main/java/aQute/lib/json/Encoder.java | 1 + .../java/aQute/lib/json/StringHandler.java | 1 + .../java/aQute/lib/spring/JPAComponent.java | 1 + .../java/aQute/lib/spring/SpringXMLType.java | 1 + .../src/main/java/aQute/lib/tag/Tag.java | 1 + .../src/main/java/aQute/libg/cafs/CAFS.java | 9 +- .../java/aQute/libg/clauses/Selector.java | 1 + .../main/java/aQute/libg/command/Command.java | 4 + .../java/aQute/libg/cryptography/Digest.java | 2 + .../java/aQute/libg/sed/ReplacerAdapter.java | 75 +++---- .../main/java/aQute/libg/tarjan/Tarjan.java | 1 + 88 files changed, 695 insertions(+), 272 deletions(-) diff --git a/bundleplugin/src/main/java/aQute/bnd/build/Container.java b/bundleplugin/src/main/java/aQute/bnd/build/Container.java index 8a721c98ee1..0de335d8c72 100644 --- a/bundleplugin/src/main/java/aQute/bnd/build/Container.java +++ b/bundleplugin/src/main/java/aQute/bnd/build/Container.java @@ -103,12 +103,14 @@ public String getError() { return error; } + @Override public boolean equals(Object other) { if (other instanceof Container) return file.equals(((Container) other).file); return false; } + @Override public int hashCode() { return file.hashCode(); } @@ -122,6 +124,7 @@ public Project getProject() { * * @return */ + @Override public String toString() { if (getError() != null) return "/error/" + getError(); diff --git a/bundleplugin/src/main/java/aQute/bnd/build/Project.java b/bundleplugin/src/main/java/aQute/bnd/build/Project.java index 06a4f8e17a6..9c5c2ec78fa 100644 --- a/bundleplugin/src/main/java/aQute/bnd/build/Project.java +++ b/bundleplugin/src/main/java/aQute/bnd/build/Project.java @@ -14,6 +14,7 @@ import aQute.bnd.osgi.*; import aQute.bnd.osgi.eclipse.*; import aQute.bnd.service.*; +import aQute.bnd.service.RepositoryPlugin.PutResult; import aQute.bnd.service.RepositoryPlugin.Strategy; import aQute.bnd.service.action.*; import aQute.bnd.version.*; @@ -146,6 +147,7 @@ public Workspace getWorkspace() { return workspace; } + @Override public String toString() { return getBase().getName(); } @@ -202,7 +204,9 @@ public synchronized void prepare() throws Exception { // Set default bin directory output = getOutput0(); if (!output.exists()) { - output.mkdirs(); + if (!output.mkdirs()) { + throw new IOException("Could not create directory " + output); + } getWorkspace().changedFile(output); } if (!output.isDirectory()) @@ -296,10 +300,12 @@ private File getOutput0() { /** * */ - private File getTarget0() { + private File getTarget0() throws IOException { File target = getFile(getProperty("target", "generated")); if (!target.exists()) { - target.mkdirs(); + if (!target.mkdirs()) { + throw new IOException("Could not create directory " + target); + } getWorkspace().changedFile(target); } return target; @@ -809,15 +815,16 @@ private String list(String[] args, Collection< ? > list) { return join(list, separator); } + @Override protected Object[] getMacroDomains() { return new Object[] { workspace }; } - public File release(Jar jar) throws Exception { + public File release(String jarName, InputStream jarStream) throws Exception { String name = getProperty(Constants.RELEASEREPO); - return release(name, jar); + return release(name, jarName, jarStream); } /** @@ -825,11 +832,12 @@ public File release(Jar jar) throws Exception { * * @param name * The repository name - * @param jar + * @param jarName + * @param jarStream * @return * @throws Exception */ - public File release(String name, Jar jar) throws Exception { + public File release(String name, String jarName, InputStream jarStream) throws Exception { trace("release %s", name); List plugins = getPlugins(RepositoryPlugin.class); RepositoryPlugin rp = null; @@ -848,14 +856,11 @@ public File release(String name, Jar jar) throws Exception { if (rp != null) { try { - File file = rp.put(jar); - trace("Released %s to file %s in repository %s", jar.getName(), file, rp); + PutResult r = rp.put(jarStream, new RepositoryPlugin.PutOptions()); + trace("Released %s to %s in repository %s", jarName, r.artifact, rp); } catch (Exception e) { - msgs.Release_Into_Exception_(jar, rp, e); - } - finally { - jar.close(); + msgs.Release_Into_Exception_(jarName, rp, e); } } else if (name == null) msgs.NoNameForReleaseRepository(); @@ -890,15 +895,8 @@ public void release(String name, boolean test) throws Exception { } trace("build ", Arrays.toString(jars)); for (File jar : jars) { - Jar j = new Jar(jar); - try { - release(name, j); - } - finally { - j.close(); - } + release(name, jar.getName(), new BufferedInputStream(new FileInputStream(jar))); } - } /** @@ -1114,17 +1112,13 @@ public void deploy(String name, File file) throws Exception { } if (rp != null) { - Jar jar = new Jar(file); try { - rp.put(jar); + rp.put(new BufferedInputStream(new FileInputStream(file)), new RepositoryPlugin.PutOptions()); return; } catch (Exception e) { msgs.DeployingFile_On_Exception_(file, rp.getName(), e); } - finally { - jar.close(); - } return; } trace("No repo found " + file); @@ -1155,22 +1149,16 @@ public void deploy() throws Exception { } File[] outputs = getBuildFiles(); for (File output : outputs) { - Jar jar = new Jar(output); - try { for (Deploy d : getPlugins(Deploy.class)) { - trace("Deploying %s to: %s", jar, d); + trace("Deploying %s to: %s", output.getName(), d); try { - if (d.deploy(this, jar)) + if (d.deploy(this, output.getName(), new BufferedInputStream(new FileInputStream(output)))) trace("deployed %s successfully to %s", output, d); } catch (Exception e) { msgs.Deploying(e); } } - } - finally { - jar.close(); - } } } @@ -1452,8 +1440,12 @@ public File saveBuild(Jar jar) throws Exception { if (!f.exists() || f.lastModified() < jar.lastModified()) { reportNewer(f.lastModified(), jar); f.delete(); - if (!f.getParentFile().isDirectory()) - f.getParentFile().mkdirs(); + File fp = f.getParentFile(); + if (!fp.isDirectory()) { + if (!fp.exists() && !fp.mkdirs()) { + throw new IOException("Could not create directory " + fp); + } + } jar.write(f); getWorkspace().changedFile(f); @@ -1491,6 +1483,7 @@ private void reportNewer(long lastModified, Jar jar) { /** * Refresh if we are based on stale data. This also implies our workspace. */ + @Override public boolean refresh() { boolean changed = false; if (isCnf()) { @@ -1503,6 +1496,7 @@ public boolean isCnf() { return getBase().getName().equals(Workspace.CNFDIR); } + @Override public void propertiesChanged() { super.propertiesChanged(); preparedPaths = false; @@ -1568,12 +1562,16 @@ public void clean() throws Exception { File target = getTarget0(); if (target.isDirectory() && target.getParentFile() != null) { IO.delete(target); - target.mkdirs(); + if (!target.exists() && !target.mkdirs()) { + throw new IOException("Could not create directory " + target); + } } File output = getOutput0(); if (getOutput().isDirectory()) IO.delete(output); - output.mkdirs(); + if (!output.exists() && !output.mkdirs()) { + throw new IOException("Could not create directory " + output); + } } public File[] build() throws Exception { @@ -2052,7 +2050,10 @@ void updatePackageInfoFile(String packageName, Version newVersion) throws Except String path = packageName.replace('.', '/') + "/packageinfo"; File binary = IO.getFile(getOutput(), path); - binary.getParentFile().mkdirs(); + File bp = binary.getParentFile(); + if (!bp.exists() && !bp.mkdirs()) { + throw new IOException("Could not create directory " + bp); + } IO.copy(file, binary); refresh(); diff --git a/bundleplugin/src/main/java/aQute/bnd/build/ProjectBuilder.java b/bundleplugin/src/main/java/aQute/bnd/build/ProjectBuilder.java index 5cf4f0e558a..774934af7cf 100644 --- a/bundleplugin/src/main/java/aQute/bnd/build/ProjectBuilder.java +++ b/bundleplugin/src/main/java/aQute/bnd/build/ProjectBuilder.java @@ -27,12 +27,14 @@ public long lastModified() { /** * We put our project and our workspace on the macro path. */ + @Override protected Object[] getMacroDomains() { return new Object[] { project, project.getWorkspace() }; } + @Override public Builder getSubBuilder() throws Exception { return project.getBuilder(this); } @@ -41,6 +43,7 @@ public Project getProject() { return project; } + @Override public void init() { try { if (!initialized) { @@ -68,6 +71,7 @@ public void init() { } } + @Override public List getClasspath() { init(); return super.getClasspath(); diff --git a/bundleplugin/src/main/java/aQute/bnd/build/ProjectMessages.java b/bundleplugin/src/main/java/aQute/bnd/build/ProjectMessages.java index 57367f6d7df..f692abb7328 100644 --- a/bundleplugin/src/main/java/aQute/bnd/build/ProjectMessages.java +++ b/bundleplugin/src/main/java/aQute/bnd/build/ProjectMessages.java @@ -3,7 +3,6 @@ import java.io.*; import java.util.*; -import aQute.bnd.osgi.*; import aQute.bnd.service.*; import aQute.bnd.service.RepositoryPlugin.Strategy; import aQute.bnd.version.*; @@ -39,7 +38,7 @@ public interface ProjectMessages extends Messages { ERROR ReleaseRepository_NotFoundIn_(String name, List plugins); - ERROR Release_Into_Exception_(Jar jar, RepositoryPlugin rp, Exception e); + ERROR Release_Into_Exception_(String jar, RepositoryPlugin rp, Exception e); ERROR NoScripters_(String script); diff --git a/bundleplugin/src/main/java/aQute/bnd/build/ProjectTester.java b/bundleplugin/src/main/java/aQute/bnd/build/ProjectTester.java index 86ce2e38fcd..4549624ff1a 100644 --- a/bundleplugin/src/main/java/aQute/bnd/build/ProjectTester.java +++ b/bundleplugin/src/main/java/aQute/bnd/build/ProjectTester.java @@ -63,7 +63,9 @@ public void setContinuous(boolean b) { } public boolean prepare() throws Exception { - reportDir.mkdirs(); + if (!reportDir.exists() && !reportDir.mkdirs()) { + throw new IOException("Could not create directory " + reportDir); + } for (File file : reportDir.listFiles()) { file.delete(); } diff --git a/bundleplugin/src/main/java/aQute/bnd/build/ReflectAction.java b/bundleplugin/src/main/java/aQute/bnd/build/ReflectAction.java index 3c3ee1653ef..7a0f855d9d9 100644 --- a/bundleplugin/src/main/java/aQute/bnd/build/ReflectAction.java +++ b/bundleplugin/src/main/java/aQute/bnd/build/ReflectAction.java @@ -16,6 +16,7 @@ public void execute(Project project, String action) throws Exception { m.invoke(project); } + @Override public String toString() { return "ra:" + what; } diff --git a/bundleplugin/src/main/java/aQute/bnd/build/Workspace.java b/bundleplugin/src/main/java/aQute/bnd/build/Workspace.java index 9111773c737..0044b11213d 100644 --- a/bundleplugin/src/main/java/aQute/bnd/build/Workspace.java +++ b/bundleplugin/src/main/java/aQute/bnd/build/Workspace.java @@ -81,7 +81,9 @@ public static Workspace getWorkspace(File parent) throws Exception { public Workspace(File dir) throws Exception { dir = dir.getAbsoluteFile(); - dir.mkdirs(); + if (!dir.exists() && !dir.mkdirs()) { + throw new IOException("Could not create directory " + dir); + } assert dir.isDirectory(); File buildDir = new File(dir, BNDDIR).getAbsoluteFile(); @@ -123,6 +125,7 @@ public Collection getCurrentProjects() { return models.values(); } + @Override public boolean refresh() { if (super.refresh()) { for (Project project : getCurrentProjects()) { @@ -261,19 +264,23 @@ class CachedFileRepo extends FileRepo { super("cache", getFile(buildDir, CACHEDIR), false); } + @Override public String toString() { return "bnd-cache"; } + @Override protected void 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 (!inited) { inited = true; - root.mkdirs(); + if (!root.exists() && !root.mkdirs()) { + throw new IOException("Could not create cache directory " + root); + } if (!root.isDirectory()) - throw new IllegalArgumentException("Cannot create cache dir " + root); + throw new IllegalArgumentException("Cache directory " + root + " not a directory"); InputStream in = getClass().getResourceAsStream(EMBEDDED_REPO); if (in != null) @@ -296,7 +303,10 @@ void unzip(InputStream in, File dir) throws Exception { if (!jentry.isDirectory()) { File dest = Processor.getFile(dir, jentry.getName()); if (!dest.isFile() || dest.lastModified() < jentry.getTime() || jentry.getTime() == 0) { - dest.getParentFile().mkdirs(); + File dp = dest.getParentFile(); + if (!dp.exists() && !dp.mkdirs()) { + throw new IOException("Could not create directory " + dp); + } FileOutputStream out = new FileOutputStream(dest); try { copy(jin, out); diff --git a/bundleplugin/src/main/java/aQute/bnd/build/WorkspaceRepository.java b/bundleplugin/src/main/java/aQute/bnd/build/WorkspaceRepository.java index 451bd770736..c52b7f1eb81 100644 --- a/bundleplugin/src/main/java/aQute/bnd/build/WorkspaceRepository.java +++ b/bundleplugin/src/main/java/aQute/bnd/build/WorkspaceRepository.java @@ -86,7 +86,7 @@ public boolean canWrite() { return false; } - public File put(Jar jar) throws Exception { + public PutResult put(InputStream stream, PutOptions options) throws Exception { return null; } diff --git a/bundleplugin/src/main/java/aQute/bnd/build/packageinfo b/bundleplugin/src/main/java/aQute/bnd/build/packageinfo index 0ff767436f9..084a0d4e363 100644 --- a/bundleplugin/src/main/java/aQute/bnd/build/packageinfo +++ b/bundleplugin/src/main/java/aQute/bnd/build/packageinfo @@ -1 +1 @@ -version 1.45.0 +version 2.0.0 diff --git a/bundleplugin/src/main/java/aQute/bnd/compatibility/Access.java b/bundleplugin/src/main/java/aQute/bnd/compatibility/Access.java index ac8bb3749f9..1fcb64074bf 100644 --- a/bundleplugin/src/main/java/aQute/bnd/compatibility/Access.java +++ b/bundleplugin/src/main/java/aQute/bnd/compatibility/Access.java @@ -19,6 +19,7 @@ public static Access modifier(int mod) { return PACKAGE; } + @Override public String toString() { return super.toString().toLowerCase(); } diff --git a/bundleplugin/src/main/java/aQute/bnd/compatibility/GenericParameter.java b/bundleplugin/src/main/java/aQute/bnd/compatibility/GenericParameter.java index 5118bf3c86d..e801a8ae389 100644 --- a/bundleplugin/src/main/java/aQute/bnd/compatibility/GenericParameter.java +++ b/bundleplugin/src/main/java/aQute/bnd/compatibility/GenericParameter.java @@ -13,6 +13,7 @@ public GenericParameter(String name, GenericType[] bounds) { }; } + @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append(name); diff --git a/bundleplugin/src/main/java/aQute/bnd/compatibility/Kind.java b/bundleplugin/src/main/java/aQute/bnd/compatibility/Kind.java index 42626f19c93..2e9f5cd5949 100644 --- a/bundleplugin/src/main/java/aQute/bnd/compatibility/Kind.java +++ b/bundleplugin/src/main/java/aQute/bnd/compatibility/Kind.java @@ -6,6 +6,7 @@ public enum Kind { ROOT, CLASS, FIELD, CONSTRUCTOR, METHOD, UNKNOWN; + @Override public String toString() { return super.toString().toLowerCase(); } diff --git a/bundleplugin/src/main/java/aQute/bnd/compatibility/Scope.java b/bundleplugin/src/main/java/aQute/bnd/compatibility/Scope.java index 43dccbdf7a3..c44f3bf25cb 100644 --- a/bundleplugin/src/main/java/aQute/bnd/compatibility/Scope.java +++ b/bundleplugin/src/main/java/aQute/bnd/compatibility/Scope.java @@ -68,6 +68,7 @@ public void setBase(GenericType typeSignature) { base = typeSignature; } + @Override public String toString() { StringBuilder sb = new StringBuilder(); diff --git a/bundleplugin/src/main/java/aQute/bnd/component/AnnotationReader.java b/bundleplugin/src/main/java/aQute/bnd/component/AnnotationReader.java index 1ca3af7b699..09c5f255d74 100644 --- a/bundleplugin/src/main/java/aQute/bnd/component/AnnotationReader.java +++ b/bundleplugin/src/main/java/aQute/bnd/component/AnnotationReader.java @@ -129,6 +129,7 @@ protected String referredMethod(Analyzer analyzer, ReferenceDef rdef, String val return null; } + @Override public void annotation(Annotation annotation) { try { java.lang.annotation.Annotation a = annotation.getAnnotation(); diff --git a/bundleplugin/src/main/java/aQute/bnd/component/DSAnnotations.java b/bundleplugin/src/main/java/aQute/bnd/component/DSAnnotations.java index e66ad0c466b..f3840f35a15 100644 --- a/bundleplugin/src/main/java/aQute/bnd/component/DSAnnotations.java +++ b/bundleplugin/src/main/java/aQute/bnd/component/DSAnnotations.java @@ -29,15 +29,13 @@ public boolean analyzeJar(Analyzer analyzer) throws Exception { if (instruction.matches(c.getFQN())) { if (instruction.isNegated()) break; - else { - ComponentDef definition = AnnotationReader.getDefinition(c, analyzer); - if (definition != null) { - definition.sortReferences(); - definition.prepare(analyzer); - String name = "OSGI-INF/" + definition.name + ".xml"; - names.add(name); - analyzer.getJar().putResource(name, new TagResource(definition.getTag())); - } + ComponentDef definition = AnnotationReader.getDefinition(c, analyzer); + if (definition != null) { + definition.sortReferences(); + definition.prepare(analyzer); + String name = "OSGI-INF/" + definition.name + ".xml"; + names.add(name); + analyzer.getJar().putResource(name, new TagResource(definition.getTag())); } } } diff --git a/bundleplugin/src/main/java/aQute/bnd/component/HeaderReader.java b/bundleplugin/src/main/java/aQute/bnd/component/HeaderReader.java index a7940278041..aa1e6e72b89 100644 --- a/bundleplugin/src/main/java/aQute/bnd/component/HeaderReader.java +++ b/bundleplugin/src/main/java/aQute/bnd/component/HeaderReader.java @@ -91,6 +91,7 @@ public Tag createComponentTag(String name, String impl, Map info clazz.parseClassFileWithCollector(new ClassDataCollector() { + @Override public void method(MethodDef md) { Set allowedParams = allowed; String lifecycleName = null; diff --git a/bundleplugin/src/main/java/aQute/bnd/component/ReferenceDef.java b/bundleplugin/src/main/java/aQute/bnd/component/ReferenceDef.java index fc09c52771b..cb4d4896484 100644 --- a/bundleplugin/src/main/java/aQute/bnd/component/ReferenceDef.java +++ b/bundleplugin/src/main/java/aQute/bnd/component/ReferenceDef.java @@ -88,6 +88,7 @@ static > T max(T a, T b) { return b; } + @Override public String toString() { return name; } diff --git a/bundleplugin/src/main/java/aQute/bnd/component/TagResource.java b/bundleplugin/src/main/java/aQute/bnd/component/TagResource.java index 1155d99e6f2..814a2b628c4 100644 --- a/bundleplugin/src/main/java/aQute/bnd/component/TagResource.java +++ b/bundleplugin/src/main/java/aQute/bnd/component/TagResource.java @@ -12,6 +12,7 @@ public TagResource(Tag tag) { this.tag = tag; } + @Override public void write(OutputStream out) throws UnsupportedEncodingException { OutputStreamWriter ow = new OutputStreamWriter(out, "UTF-8"); PrintWriter pw = new PrintWriter(ow); @@ -24,6 +25,7 @@ public void write(OutputStream out) throws UnsupportedEncodingException { } } + @Override public long lastModified() { return 0; } diff --git a/bundleplugin/src/main/java/aQute/bnd/differ/DiffImpl.java b/bundleplugin/src/main/java/aQute/bnd/differ/DiffImpl.java index 57c7da589d9..ef21f65e4a1 100644 --- a/bundleplugin/src/main/java/aQute/bnd/differ/DiffImpl.java +++ b/bundleplugin/src/main/java/aQute/bnd/differ/DiffImpl.java @@ -180,10 +180,12 @@ public String getName() { return children; } + @Override public String toString() { return String.format("%-10s %-10s %s", getDelta(), getType(), getName()); } + @Override public boolean equals(Object other) { if (other instanceof DiffImpl) { DiffImpl o = (DiffImpl) other; @@ -192,6 +194,7 @@ public boolean equals(Object other) { return false; } + @Override public int hashCode() { return getDelta().hashCode() ^ getType().hashCode() ^ getName().hashCode(); } diff --git a/bundleplugin/src/main/java/aQute/bnd/differ/Element.java b/bundleplugin/src/main/java/aQute/bnd/differ/Element.java index 3d27f6244d2..6b74b4dbad3 100644 --- a/bundleplugin/src/main/java/aQute/bnd/differ/Element.java +++ b/bundleplugin/src/main/java/aQute/bnd/differ/Element.java @@ -100,6 +100,7 @@ public int compareTo(Tree other) { return type.compareTo(other.getType()); } + @Override public boolean equals(Object other) { if (other == null || getClass() != other.getClass()) return false; @@ -107,6 +108,7 @@ public boolean equals(Object other) { return compareTo((Element) other) == 0; } + @Override public int hashCode() { return type.hashCode() ^ name.hashCode(); } @@ -135,6 +137,7 @@ public Element get(String name) { return null; } + @Override public String toString() { return type + " " + name + " (" + add + "/" + remove + ")"; } diff --git a/bundleplugin/src/main/java/aQute/bnd/filerepo/FileRepo.java b/bundleplugin/src/main/java/aQute/bnd/filerepo/FileRepo.java index 4f5a4367abb..a8966a41321 100644 --- a/bundleplugin/src/main/java/aQute/bnd/filerepo/FileRepo.java +++ b/bundleplugin/src/main/java/aQute/bnd/filerepo/FileRepo.java @@ -4,7 +4,6 @@ import java.util.*; import java.util.regex.*; -import aQute.bnd.osgi.*; import aQute.bnd.version.*; public class FileRepo { @@ -97,9 +96,11 @@ public File get(String bsn, VersionRange range, int strategy) throws Exception { return files[files.length - 1]; } - public File put(String bsn, Version version) { + public File put(String bsn, Version version) throws IOException { File dir = new File(root, bsn); - dir.mkdirs(); + if (!dir.exists() && !dir.mkdirs()) { + throw new IOException("Could not create directory " + dir); + } File file = new File(dir, bsn + "-" + version.getMajor() + "." + version.getMinor() + "." + version.getMicro() + ".jar"); return file; diff --git a/bundleplugin/src/main/java/aQute/bnd/header/Attrs.java b/bundleplugin/src/main/java/aQute/bnd/header/Attrs.java index 0124ff1f5d1..d0c41ba2032 100644 --- a/bundleplugin/src/main/java/aQute/bnd/header/Attrs.java +++ b/bundleplugin/src/main/java/aQute/bnd/header/Attrs.java @@ -3,7 +3,6 @@ import java.util.*; import java.util.regex.*; -import aQute.bnd.osgi.*; import aQute.bnd.version.*; import aQute.lib.collections.*; @@ -220,6 +219,7 @@ public String getVersion() { return get("version"); } + @Override public String toString() { StringBuilder sb = new StringBuilder(); append(sb); @@ -237,11 +237,13 @@ public void append(StringBuilder sb) { } } + @Override @Deprecated public boolean equals(Object other) { return super.equals(other); } + @Override @Deprecated public int hashCode() { return super.hashCode(); diff --git a/bundleplugin/src/main/java/aQute/bnd/header/Parameters.java b/bundleplugin/src/main/java/aQute/bnd/header/Parameters.java index 413b6a5ac9a..7666f4b9e7e 100644 --- a/bundleplugin/src/main/java/aQute/bnd/header/Parameters.java +++ b/bundleplugin/src/main/java/aQute/bnd/header/Parameters.java @@ -148,6 +148,7 @@ public Collection values() { return map.values(); } + @Override public String toString() { StringBuilder sb = new StringBuilder(); append(sb); @@ -168,11 +169,13 @@ public void append(StringBuilder sb) { } } + @Override @Deprecated public boolean equals(Object other) { return super.equals(other); } + @Override @Deprecated public int hashCode() { return super.hashCode(); diff --git a/bundleplugin/src/main/java/aQute/bnd/make/calltree/CalltreeResource.java b/bundleplugin/src/main/java/aQute/bnd/make/calltree/CalltreeResource.java index 505cfc20281..14cba4b62fb 100644 --- a/bundleplugin/src/main/java/aQute/bnd/make/calltree/CalltreeResource.java +++ b/bundleplugin/src/main/java/aQute/bnd/make/calltree/CalltreeResource.java @@ -47,6 +47,7 @@ public CalltreeResource(Collection values) { * We set the last modified to 0 so this resource does not force a new JAR * if all other resources are up to date. */ + @Override public long lastModified() { return 0; } @@ -55,6 +56,7 @@ public long lastModified() { * The write method is called to write the resource. We just call the static * method. */ + @Override public void write(OutputStream out) throws Exception { OutputStreamWriter osw = new OutputStreamWriter(out, Constants.DEFAULT_CHARSET); PrintWriter pw = new PrintWriter(osw); @@ -87,6 +89,7 @@ public static void writeCalltree(PrintWriter out, Collection classes) thr Clazz.MethodDef source; // Before a method is parsed + @Override public void method(Clazz.MethodDef source) { this.source = source; xref(using, source, null); diff --git a/bundleplugin/src/main/java/aQute/bnd/make/component/ComponentAnnotationReader.java b/bundleplugin/src/main/java/aQute/bnd/make/component/ComponentAnnotationReader.java index c9d60b36e39..b9d7e4ffb4e 100644 --- a/bundleplugin/src/main/java/aQute/bnd/make/component/ComponentAnnotationReader.java +++ b/bundleplugin/src/main/java/aQute/bnd/make/component/ComponentAnnotationReader.java @@ -80,6 +80,7 @@ public static Map getDefinition(Clazz c, Reporter reporter) throw return r.map; } + @Override public void annotation(Annotation annotation) { String fqn = annotation.getName().getFQN(); diff --git a/bundleplugin/src/main/java/aQute/bnd/make/component/ServiceComponent.java b/bundleplugin/src/main/java/aQute/bnd/make/component/ServiceComponent.java index af863c65834..5367c9383e0 100644 --- a/bundleplugin/src/main/java/aQute/bnd/make/component/ServiceComponent.java +++ b/bundleplugin/src/main/java/aQute/bnd/make/component/ServiceComponent.java @@ -11,11 +11,9 @@ import aQute.bnd.header.*; import aQute.bnd.make.metatype.*; import aQute.bnd.osgi.*; -import aQute.bnd.osgi.Clazz.MethodDef; import aQute.bnd.osgi.Clazz.QUERY; import aQute.bnd.osgi.Descriptors.TypeRef; import aQute.bnd.service.*; -import aQute.bnd.version.*; import aQute.lib.tag.Tag; /** diff --git a/bundleplugin/src/main/java/aQute/bnd/make/coverage/Coverage.java b/bundleplugin/src/main/java/aQute/bnd/make/coverage/Coverage.java index 6ca638cb0ea..28782485ef4 100644 --- a/bundleplugin/src/main/java/aQute/bnd/make/coverage/Coverage.java +++ b/bundleplugin/src/main/java/aQute/bnd/make/coverage/Coverage.java @@ -37,6 +37,7 @@ private static void crossRef(Collection source, final Map", "()V"); // TODO @@ -53,6 +54,7 @@ public void implementsInterfaces(TypeRef names[]) { } // Method definitions + @Override public void method(MethodDef source) { this.source = source; } @@ -77,10 +79,12 @@ public int compare(MethodDef a, MethodDef b) { for (final Clazz clazz : sources) { clazz.parseClassFileWithCollector(new ClassDataCollector() { + @Override public boolean classStart(int access, TypeRef name) { return clazz.isPublic(); } + @Override public void method(MethodDef source) { if (source.isPublic() || source.isProtected()) catalog.put(source, new ArrayList()); diff --git a/bundleplugin/src/main/java/aQute/bnd/make/metatype/MetaTypeReader.java b/bundleplugin/src/main/java/aQute/bnd/make/metatype/MetaTypeReader.java index 4f57467512a..be717e2519c 100644 --- a/bundleplugin/src/main/java/aQute/bnd/make/metatype/MetaTypeReader.java +++ b/bundleplugin/src/main/java/aQute/bnd/make/metatype/MetaTypeReader.java @@ -171,6 +171,7 @@ private String[] parseOptionValues(Clazz c) throws Exception { final List values = Create.list(); c.parseClassFileWithCollector(new ClassDataCollector() { + @Override public void field(Clazz.FieldDef def) { if (def.isEnum()) { values.add(def.getName()); @@ -236,6 +237,7 @@ public void annotation(Annotation annotation) { } + @Override public void write(OutputStream out) throws IOException { try { finish(); diff --git a/bundleplugin/src/main/java/aQute/bnd/maven/MavenCommand.java b/bundleplugin/src/main/java/aQute/bnd/maven/MavenCommand.java index 7fb4dfdf4e2..b1bdc42e07e 100644 --- a/bundleplugin/src/main/java/aQute/bnd/maven/MavenCommand.java +++ b/bundleplugin/src/main/java/aQute/bnd/maven/MavenCommand.java @@ -60,7 +60,9 @@ public void run(String args[], int i) throws Exception { trace("temp dir " + temp); IO.delete(temp); - temp.mkdirs(); + if (!temp.exists() && !temp.mkdirs()) { + throw new IOException("Could not create directory " + temp); + } if (!temp.isDirectory()) throw new IOException("Cannot create temp directory"); @@ -210,7 +212,9 @@ else if (option.startsWith("-properties")) { } File original = getFile(temp, "original"); - original.mkdirs(); + if (!original.exists() && !original.mkdirs()) { + throw new IOException("Could not create directory " + original); + } binaryJar.expand(original); binaryJar.calcChecksums(null); @@ -272,7 +276,9 @@ else if (option.startsWith("-properties")) { trace("creating bundle dir"); File bundle = new File(temp, "bundle"); - bundle.mkdirs(); + if (!bundle.exists() && !bundle.mkdirs()) { + throw new IOException("Could not create directory " + bundle); + } String prefix = pom.getArtifactId() + "-" + pom.getVersion(); File binaryFile = new File(bundle, prefix + ".jar"); @@ -400,7 +406,9 @@ private void sign(File file, String passphrase) throws Exception { private Jar javadoc(File source, Set exports, Manifest m, Properties p) throws Exception { File tmp = new File(temp, "javadoc"); - tmp.mkdirs(); + if (!tmp.exists() && !tmp.mkdirs()) { + throw new IOException("Could not create directory " + tmp); + } Command command = new Command(); command.add(getProperty("javadoc", "javadoc")); diff --git a/bundleplugin/src/main/java/aQute/bnd/maven/MavenDependencyGraph.java b/bundleplugin/src/main/java/aQute/bnd/maven/MavenDependencyGraph.java index bbc45b82028..e9e928e4ae8 100644 --- a/bundleplugin/src/main/java/aQute/bnd/maven/MavenDependencyGraph.java +++ b/bundleplugin/src/main/java/aQute/bnd/maven/MavenDependencyGraph.java @@ -63,6 +63,7 @@ public void add(Artifact artifact) { dependencies.add(artifact); } + @Override public String toString() { return groupId + "." + artifactId + "-" + version + "[" + scope + "," + optional + "]"; } diff --git a/bundleplugin/src/main/java/aQute/bnd/maven/MavenDeploy.java b/bundleplugin/src/main/java/aQute/bnd/maven/MavenDeploy.java index ff383b40a14..592b3f989a2 100644 --- a/bundleplugin/src/main/java/aQute/bnd/maven/MavenDeploy.java +++ b/bundleplugin/src/main/java/aQute/bnd/maven/MavenDeploy.java @@ -40,56 +40,64 @@ public void setReporter(Reporter processor) { /** */ - public boolean deploy(Project project, Jar original) throws Exception { + public boolean deploy(Project project, String jarName, InputStream jarStream) throws Exception { Parameters deploy = project.parseHeader(project.getProperty(Constants.DEPLOY)); Map maven = deploy.get(repository); if (maven == null) return false; // we're not playing for this bundle - project.progress("deploying %s to Maven repo: %s", original, repository); + project.progress("deploying %s to Maven repo: %s", jarName, repository); File target = project.getTarget(); File tmp = Processor.getFile(target, repository); - tmp.mkdirs(); - - Manifest manifest = original.getManifest(); - if (manifest == null) - project.error("Jar has no manifest: %s", original); - else { - project.progress("Writing pom.xml"); - PomResource pom = new PomResource(manifest); - pom.setProperties(maven); - File pomFile = write(tmp, pom, "pom.xml"); - - Jar main = new Jar("main"); - Jar src = new Jar("src"); - try { - split(original, main, src); - Parameters exports = project.parseHeader(manifest.getMainAttributes() - .getValue(Constants.EXPORT_PACKAGE)); - File jdoc = new File(tmp, "jdoc"); - jdoc.mkdirs(); - project.progress("Generating Javadoc for: " + exports.keySet()); - Jar javadoc = javadoc(jdoc, project, exports.keySet()); - project.progress("Writing javadoc jar"); - File javadocFile = write(tmp, new JarResource(javadoc), "javadoc.jar"); - project.progress("Writing main file"); - File mainFile = write(tmp, new JarResource(main), "main.jar"); - project.progress("Writing sources file"); - File srcFile = write(tmp, new JarResource(main), "src.jar"); - - project.progress("Deploying main file"); - maven_gpg_sign_and_deploy(project, mainFile, null, pomFile); - project.progress("Deploying main sources file"); - maven_gpg_sign_and_deploy(project, srcFile, "sources", null); - project.progress("Deploying main javadoc file"); - maven_gpg_sign_and_deploy(project, javadocFile, "javadoc", null); + if (!tmp.exists() && !tmp.mkdirs()) { + throw new IOException("Could not create directory " + tmp); + } + Jar original = new Jar(jarName, jarStream); + try { + Manifest manifest = original.getManifest(); + if (manifest == null) + project.error("Jar has no manifest: %s", original); + else { + project.progress("Writing pom.xml"); + PomResource pom = new PomResource(manifest); + pom.setProperties(maven); + File pomFile = write(tmp, pom, "pom.xml"); + + Jar main = new Jar("main"); + Jar src = new Jar("src"); + try { + split(original, main, src); + Parameters exports = project.parseHeader(manifest.getMainAttributes().getValue( + Constants.EXPORT_PACKAGE)); + File jdoc = new File(tmp, "jdoc"); + jdoc.mkdirs(); + project.progress("Generating Javadoc for: " + exports.keySet()); + Jar javadoc = javadoc(jdoc, project, exports.keySet()); + project.progress("Writing javadoc jar"); + File javadocFile = write(tmp, new JarResource(javadoc), "javadoc.jar"); + project.progress("Writing main file"); + File mainFile = write(tmp, new JarResource(main), "main.jar"); + project.progress("Writing sources file"); + File srcFile = write(tmp, new JarResource(main), "src.jar"); + + project.progress("Deploying main file"); + maven_gpg_sign_and_deploy(project, mainFile, null, pomFile); + project.progress("Deploying main sources file"); + maven_gpg_sign_and_deploy(project, srcFile, "sources", null); + project.progress("Deploying main javadoc file"); + maven_gpg_sign_and_deploy(project, javadocFile, "javadoc", null); + + } + finally { + main.close(); + src.close(); + } } - finally { - main.close(); - src.close(); - } + } + finally { + original.close(); } return true; } diff --git a/bundleplugin/src/main/java/aQute/bnd/maven/MavenDeployCmd.java b/bundleplugin/src/main/java/aQute/bnd/maven/MavenDeployCmd.java index 10829ca0a75..8d1909377b5 100644 --- a/bundleplugin/src/main/java/aQute/bnd/maven/MavenDeployCmd.java +++ b/bundleplugin/src/main/java/aQute/bnd/maven/MavenDeployCmd.java @@ -85,7 +85,9 @@ public boolean deploy(Project project, Jar original) throws Exception { project.progress("deploying %s to Maven repo: %s", original, repository); File target = project.getTarget(); File tmp = Processor.getFile(target, repository); - tmp.mkdirs(); + if (!tmp.exists() && !tmp.mkdirs()) { + throw new IOException("Could not create directory " + tmp); + } Manifest manifest = original.getManifest(); if (manifest == null) @@ -103,7 +105,9 @@ public boolean deploy(Project project, Jar original) throws Exception { Parameters exports = project.parseHeader(manifest.getMainAttributes() .getValue(Constants.EXPORT_PACKAGE)); File jdoc = new File(tmp, "jdoc"); - jdoc.mkdirs(); + if (!jdoc.exists() && !jdoc.mkdirs()) { + throw new IOException("Could not create directory " + jdoc); + } project.progress("Generating Javadoc for: " + exports.keySet()); Jar javadoc = javadoc(jdoc, project, exports.keySet()); project.progress("Writing javadoc jar"); diff --git a/bundleplugin/src/main/java/aQute/bnd/maven/MavenRepository.java b/bundleplugin/src/main/java/aQute/bnd/maven/MavenRepository.java index 7a6ff20fffc..33d21e0628d 100644 --- a/bundleplugin/src/main/java/aQute/bnd/maven/MavenRepository.java +++ b/bundleplugin/src/main/java/aQute/bnd/maven/MavenRepository.java @@ -17,6 +17,7 @@ public class MavenRepository implements RepositoryPlugin, Plugin, BsnToMavenPath Reporter reporter; String name; + @Override public String toString() { return "maven:" + root; } @@ -112,7 +113,7 @@ void find(List bsns, Pattern pattern, File base, String name) { } } - public File put(Jar jar) throws Exception { + public PutResult put(InputStream stream, PutOptions options) throws Exception { throw new IllegalStateException("Maven does not support the put command"); } diff --git a/bundleplugin/src/main/java/aQute/bnd/maven/support/CachedPom.java b/bundleplugin/src/main/java/aQute/bnd/maven/support/CachedPom.java index 5787e2950f3..d7847671d79 100644 --- a/bundleplugin/src/main/java/aQute/bnd/maven/support/CachedPom.java +++ b/bundleplugin/src/main/java/aQute/bnd/maven/support/CachedPom.java @@ -11,6 +11,7 @@ public class CachedPom extends Pom { this.maven = mavenEntry; } + @Override public File getArtifact() throws Exception { return maven.getArtifact(); } diff --git a/bundleplugin/src/main/java/aQute/bnd/maven/support/MavenEntry.java b/bundleplugin/src/main/java/aQute/bnd/maven/support/MavenEntry.java index fe185a18fed..4e153c3bb51 100644 --- a/bundleplugin/src/main/java/aQute/bnd/maven/support/MavenEntry.java +++ b/bundleplugin/src/main/java/aQute/bnd/maven/support/MavenEntry.java @@ -43,7 +43,9 @@ public class MavenEntry implements Closeable { this.pomPath = path + ".pom"; this.artifactPath = path + ".jar"; this.dir = IO.getFile(maven.repository, path).getParentFile(); - this.dir.mkdirs(); + if (!this.dir.exists() && !this.dir.mkdirs()) { + throw new ExceptionInInitializerError("Could not create directory " + this.dir); + } this.pomFile = new File(maven.repository, pomPath); this.artifactFile = new File(maven.repository, artifactPath); this.propertiesFile = new File(dir, "bnd.properties"); @@ -98,7 +100,9 @@ public CachedPom getPom(URI[] urls) throws Exception { // the file. } else { - dir.mkdirs(); + if (!dir.exists() && !dir.mkdirs()) { + throw new IOException("Could not create directory " + dir); + } // We really do not have the file // so we have to find out who has it. for (final URI url : urls) { diff --git a/bundleplugin/src/main/java/aQute/bnd/maven/support/MavenRemoteRepository.java b/bundleplugin/src/main/java/aQute/bnd/maven/support/MavenRemoteRepository.java index 93f169b195e..4609e32c47b 100644 --- a/bundleplugin/src/main/java/aQute/bnd/maven/support/MavenRemoteRepository.java +++ b/bundleplugin/src/main/java/aQute/bnd/maven/support/MavenRemoteRepository.java @@ -4,7 +4,6 @@ import java.net.*; import java.util.*; -import aQute.bnd.osgi.*; import aQute.bnd.service.*; import aQute.bnd.version.*; import aQute.lib.io.*; @@ -68,7 +67,7 @@ public boolean canWrite() { return false; } - public File put(Jar jar) throws Exception { + public PutResult put(InputStream stream, PutOptions options) throws Exception { throw new UnsupportedOperationException("cannot do put"); } diff --git a/bundleplugin/src/main/java/aQute/bnd/maven/support/Pom.java b/bundleplugin/src/main/java/aQute/bnd/maven/support/Pom.java index 0055d19c2dd..a778d8b9102 100644 --- a/bundleplugin/src/main/java/aQute/bnd/maven/support/Pom.java +++ b/bundleplugin/src/main/java/aQute/bnd/maven/support/Pom.java @@ -296,6 +296,7 @@ protected String replace(String in) { return in; } + @Override public String toString() { return groupId + "+" + artifactId + "-" + version; } diff --git a/bundleplugin/src/main/java/aQute/bnd/maven/support/ProjectPom.java b/bundleplugin/src/main/java/aQute/bnd/maven/support/ProjectPom.java index 07e10c675ac..eedff8c8bd0 100644 --- a/bundleplugin/src/main/java/aQute/bnd/maven/support/ProjectPom.java +++ b/bundleplugin/src/main/java/aQute/bnd/maven/support/ProjectPom.java @@ -136,6 +136,7 @@ public Set getDependencies(Scope action) throws Exception { // Match any macros final static Pattern MACRO = Pattern.compile("(\\$\\{\\s*([^}\\s]+)\\s*\\})"); + @Override protected String replace(String in) { System.err.println("Replce: " + in); if (in == null) { diff --git a/bundleplugin/src/main/java/aQute/bnd/maven/support/packageinfo b/bundleplugin/src/main/java/aQute/bnd/maven/support/packageinfo index 7c8de0324fd..a3d9bcc0c12 100644 --- a/bundleplugin/src/main/java/aQute/bnd/maven/support/packageinfo +++ b/bundleplugin/src/main/java/aQute/bnd/maven/support/packageinfo @@ -1 +1 @@ -version 1.0 +version 2.0 diff --git a/bundleplugin/src/main/java/aQute/bnd/osgi/Analyzer.java b/bundleplugin/src/main/java/aQute/bnd/osgi/Analyzer.java index c490e660e11..135f96c5fbf 100755 --- a/bundleplugin/src/main/java/aQute/bnd/osgi/Analyzer.java +++ b/bundleplugin/src/main/java/aQute/bnd/osgi/Analyzer.java @@ -769,6 +769,7 @@ public void mergeManifest(Manifest manifest) throws IOException { } } + @Override public void setBase(File file) { super.setBase(file); getProperties().put("project.dir", getBase().getAbsolutePath()); @@ -840,6 +841,7 @@ public Jar setJar(Jar jar) { return jar; } + @Override protected void begin() { if (inited == false) { inited = true; @@ -1466,6 +1468,7 @@ void getExportVersionsFromPackageInfo(PackageRef packageRef, Resource r, Package } } + @Override public void close() { if (diagnostics) { PrintStream out = System.err; @@ -1612,6 +1615,7 @@ public void addClasspath(File cp) throws IOException { classpath.add(jar); } + @Override public void clear() { classpath.clear(); } @@ -2447,7 +2451,10 @@ public boolean save(File output, boolean force) throws Exception { jar.lastModified() - output.lastModified()); if (!output.exists() || output.lastModified() <= jar.lastModified() || force) { - output.getParentFile().mkdirs(); + File op = output.getParentFile(); + if (!op.exists() && !op.mkdirs()) { + throw new IOException("Could not create directory " + op); + } if (source != null && output.getCanonicalPath().equals(source.getCanonicalPath())) { File bak = new File(source.getParentFile(), source.getName() + ".bak"); if (!source.renameTo(bak)) { @@ -2545,11 +2552,13 @@ public Map> getXRef(final PackageRef source, final Colle clazz.parseClassFileWithCollector(new ClassDataCollector() { Clazz.Def member; + @Override public void extendsClass(TypeRef zuper) throws Exception { if (dest.contains(zuper.getPackageRef())) xref.add(clazz.getExtends(zuper), zuper); } + @Override public void implementsInterfaces(TypeRef[] interfaces) throws Exception { for (TypeRef i : interfaces) { if (dest.contains(i.getPackageRef())) @@ -2557,6 +2566,7 @@ public void implementsInterfaces(TypeRef[] interfaces) throws Exception { } } + @Override public void referTo(TypeRef to, int modifiers) { if (to.isJava()) return; @@ -2570,10 +2580,12 @@ public void referTo(TypeRef to, int modifiers) { } + @Override public void method(Clazz.MethodDef defined) { member = defined; } + @Override public void field(Clazz.FieldDef defined) { member = defined; } diff --git a/bundleplugin/src/main/java/aQute/bnd/osgi/Annotation.java b/bundleplugin/src/main/java/aQute/bnd/osgi/Annotation.java index 37c4cadf078..0383962ec02 100644 --- a/bundleplugin/src/main/java/aQute/bnd/osgi/Annotation.java +++ b/bundleplugin/src/main/java/aQute/bnd/osgi/Annotation.java @@ -34,6 +34,7 @@ public RetentionPolicy getRetentionPolicy() { return policy; } + @Override public String toString() { return name + ":" + member + ":" + policy + ":" + elements; } diff --git a/bundleplugin/src/main/java/aQute/bnd/osgi/Builder.java b/bundleplugin/src/main/java/aQute/bnd/osgi/Builder.java index 912bad3ed95..2ee603a8307 100755 --- a/bundleplugin/src/main/java/aQute/bnd/osgi/Builder.java +++ b/bundleplugin/src/main/java/aQute/bnd/osgi/Builder.java @@ -238,7 +238,10 @@ private void doSaveManifest(Jar dot) throws Exception { f = new File(f, "MANIFEST.MF"); } f.delete(); - f.getParentFile().mkdirs(); + File fp = f.getParentFile(); + if (!fp.exists() && !fp.mkdirs()) { + throw new IOException("Could not create directory " + fp); + } OutputStream out = new FileOutputStream(f); try { Jar.writeManifest(dot.getManifest(), out); @@ -281,6 +284,7 @@ public boolean hasSources() { /** * Answer extra packages. In this case we implement conditional package. Any */ + @Override protected Jar getExtra() throws Exception { Parameters conditionals = getParameters(CONDITIONAL_PACKAGE); if (conditionals.isEmpty()) @@ -315,6 +319,7 @@ protected Jar getExtra() throws Exception { * the setup. We do not want to cleanup if we are going to verify. */ + @Override public void analyze() throws Exception { super.analyze(); cleanupVersion(getImports(), null); @@ -1078,6 +1083,7 @@ public void addSourcepath(File cp) { sourcePath.add(cp); } + @Override public void close() { super.close(); } diff --git a/bundleplugin/src/main/java/aQute/bnd/osgi/BundleId.java b/bundleplugin/src/main/java/aQute/bnd/osgi/BundleId.java index 2d711ad5c57..67f9b4a648d 100644 --- a/bundleplugin/src/main/java/aQute/bnd/osgi/BundleId.java +++ b/bundleplugin/src/main/java/aQute/bnd/osgi/BundleId.java @@ -24,10 +24,12 @@ public boolean isValid() { return Verifier.isVersion(version) && Verifier.isBsn(bsn); } + @Override public boolean equals(Object o) { return this == o || ((o instanceof BundleId) && compareTo((BundleId) o) == 0); } + @Override public int hashCode() { return bsn.hashCode() ^ version.hashCode(); } diff --git a/bundleplugin/src/main/java/aQute/bnd/osgi/Clazz.java b/bundleplugin/src/main/java/aQute/bnd/osgi/Clazz.java index e03865a2843..1a325e6b01b 100755 --- a/bundleplugin/src/main/java/aQute/bnd/osgi/Clazz.java +++ b/bundleplugin/src/main/java/aQute/bnd/osgi/Clazz.java @@ -251,11 +251,13 @@ public FieldDef(int access, String name, String descriptor) { this.descriptor = analyzer.getDescriptor(descriptor); } + @Override public String getName() { return name; } + @Override public TypeRef getType() { return descriptor.getType(); } @@ -290,6 +292,7 @@ public String getGenericReturnType() { return objectDescriptorToFQN(returnType); } + @Override public TypeRef[] getPrototype() { return null; } @@ -297,6 +300,7 @@ public String getSignature() { return signature; } + @Override public String toString() { return name; } @@ -311,6 +315,7 @@ public boolean isConstructor() { return name.equals("") || name.equals(""); } + @Override public TypeRef[] getPrototype() { return descriptor.getPrototype(); } @@ -335,16 +340,18 @@ public boolean getImplements() { } + @Override public String getName() { if (interf) return ""; - else - return ""; + return ""; } + @Override public TypeRef getType() { return type; } + @Override public TypeRef[] getPrototype() { return null; } @@ -1527,6 +1534,7 @@ public boolean is(QUERY query, Instruction instr, Analyzer analyzer) throws Exce return clazz.is(query, instr, analyzer); } + @Override public String toString() { return className.getFQN(); } diff --git a/bundleplugin/src/main/java/aQute/bnd/osgi/CombinedResource.java b/bundleplugin/src/main/java/aQute/bnd/osgi/CombinedResource.java index d38f416b577..1b103487062 100644 --- a/bundleplugin/src/main/java/aQute/bnd/osgi/CombinedResource.java +++ b/bundleplugin/src/main/java/aQute/bnd/osgi/CombinedResource.java @@ -10,6 +10,7 @@ public class CombinedResource extends WriteResource { @Override public void write(final OutputStream out) throws IOException, Exception { OutputStream unclosable = new FilterOutputStream(out) { + @Override public void close() { // Ignore } diff --git a/bundleplugin/src/main/java/aQute/bnd/osgi/Descriptors.java b/bundleplugin/src/main/java/aQute/bnd/osgi/Descriptors.java index b435b2751ff..683f96d2d76 100644 --- a/bundleplugin/src/main/java/aQute/bnd/osgi/Descriptors.java +++ b/bundleplugin/src/main/java/aQute/bnd/osgi/Descriptors.java @@ -95,6 +95,7 @@ public boolean isJava() { return java; } + @Override public String toString() { return fqn; } @@ -111,11 +112,13 @@ public int compareTo(PackageRef other) { return fqn.compareTo(other.fqn); } + @Override public boolean equals(Object o) { assert o instanceof PackageRef; return o == this; } + @Override public int hashCode() { return super.hashCode(); } @@ -207,6 +210,7 @@ public boolean isJava() { return packageRef.isJava(); } + @Override public String toString() { return fqn; } @@ -215,6 +219,7 @@ public boolean isObject() { return fqn.equals("java.lang.Object"); } + @Override public boolean equals(Object other) { assert other instanceof TypeRef; return this == other; @@ -268,6 +273,7 @@ public TypeRef getClassRef() { return component.getClassRef(); } + @Override public boolean equals(Object other) { if (other == null || other.getClass() != getClass()) return false; @@ -287,6 +293,7 @@ public boolean isJava() { return component.isJava(); } + @Override public String toString() { return component.toString() + "[]"; } @@ -457,6 +464,7 @@ public TypeRef[] getPrototype() { return prototype; } + @Override public boolean equals(Object other) { if (other == null || other.getClass() != getClass()) return false; @@ -464,10 +472,12 @@ public boolean equals(Object other) { return Arrays.equals(prototype, ((Descriptor) other).prototype) && type == ((Descriptor) other).type; } + @Override public int hashCode() { return prototype == null ? type.hashCode() : type.hashCode() ^ Arrays.hashCode(prototype); } + @Override public String toString() { return descriptor; } diff --git a/bundleplugin/src/main/java/aQute/bnd/osgi/EmbeddedResource.java b/bundleplugin/src/main/java/aQute/bnd/osgi/EmbeddedResource.java index 0aad6054cf2..ae3c4493552 100755 --- a/bundleplugin/src/main/java/aQute/bnd/osgi/EmbeddedResource.java +++ b/bundleplugin/src/main/java/aQute/bnd/osgi/EmbeddedResource.java @@ -23,6 +23,7 @@ public void write(OutputStream out) throws IOException { out.write(data); } + @Override public String toString() { return ":" + data.length + ":"; } diff --git a/bundleplugin/src/main/java/aQute/bnd/osgi/FileResource.java b/bundleplugin/src/main/java/aQute/bnd/osgi/FileResource.java index cd18cf5e84d..66635d1bc20 100755 --- a/bundleplugin/src/main/java/aQute/bnd/osgi/FileResource.java +++ b/bundleplugin/src/main/java/aQute/bnd/osgi/FileResource.java @@ -19,6 +19,7 @@ public static void build(Jar jar, File directory, Pattern doNotCopy) { traverse(jar, directory.getAbsolutePath().length(), directory, doNotCopy); } + @Override public String toString() { return ":" + file.getName() + ":"; } diff --git a/bundleplugin/src/main/java/aQute/bnd/osgi/Instruction.java b/bundleplugin/src/main/java/aQute/bnd/osgi/Instruction.java index a660169841b..d350c8aaa8a 100755 --- a/bundleplugin/src/main/java/aQute/bnd/osgi/Instruction.java +++ b/bundleplugin/src/main/java/aQute/bnd/osgi/Instruction.java @@ -145,6 +145,7 @@ public String getInput() { return input; } + @Override public String toString() { return input; } diff --git a/bundleplugin/src/main/java/aQute/bnd/osgi/Instructions.java b/bundleplugin/src/main/java/aQute/bnd/osgi/Instructions.java index bfb7e28087e..b157f889e1f 100644 --- a/bundleplugin/src/main/java/aQute/bnd/osgi/Instructions.java +++ b/bundleplugin/src/main/java/aQute/bnd/osgi/Instructions.java @@ -145,6 +145,7 @@ public Collection values() { return map.values(); } + @Override public String toString() { return map == null ? "{}" : map.toString(); } diff --git a/bundleplugin/src/main/java/aQute/bnd/osgi/Jar.java b/bundleplugin/src/main/java/aQute/bnd/osgi/Jar.java index 11c0dab4675..93c55a1d873 100755 --- a/bundleplugin/src/main/java/aQute/bnd/osgi/Jar.java +++ b/bundleplugin/src/main/java/aQute/bnd/osgi/Jar.java @@ -97,6 +97,7 @@ public void setName(String name) { this.name = name; } + @Override public String toString() { return "Jar:" + name; } @@ -768,14 +769,19 @@ public String getVersion() throws Exception { public void expand(File dir) throws Exception { check(); dir = dir.getAbsoluteFile(); - dir.mkdirs(); + if (!dir.exists() && !dir.mkdirs()) { + throw new IOException("Could not create directory " + dir); + } if (!dir.isDirectory()) { throw new IllegalArgumentException("Not a dir: " + dir.getAbsolutePath()); } for (Map.Entry entry : getResources().entrySet()) { File f = getFile(dir, entry.getKey()); - f.getParentFile().mkdirs(); + File fp = f.getParentFile(); + if (!fp.exists() && !fp.mkdirs()) { + throw new IOException("Could not create directory " + fp); + } IO.copy(entry.getValue().openInputStream(), f); } } diff --git a/bundleplugin/src/main/java/aQute/bnd/osgi/JarResource.java b/bundleplugin/src/main/java/aQute/bnd/osgi/JarResource.java index 2fb5c54e18d..1734fc9933d 100755 --- a/bundleplugin/src/main/java/aQute/bnd/osgi/JarResource.java +++ b/bundleplugin/src/main/java/aQute/bnd/osgi/JarResource.java @@ -10,10 +10,12 @@ public JarResource(Jar jar) { this.jar = jar; } + @Override public long lastModified() { return jar.lastModified(); } + @Override public void write(OutputStream out) throws Exception { try { jar.write(out); @@ -28,6 +30,7 @@ public Jar getJar() { return jar; } + @Override public String toString() { return ":" + jar.getName() + ":"; } diff --git a/bundleplugin/src/main/java/aQute/bnd/osgi/Macro.java b/bundleplugin/src/main/java/aQute/bnd/osgi/Macro.java index 20cc4a44c80..d7065962b68 100755 --- a/bundleplugin/src/main/java/aQute/bnd/osgi/Macro.java +++ b/bundleplugin/src/main/java/aQute/bnd/osgi/Macro.java @@ -895,6 +895,7 @@ public boolean contains(String key) { return previous.contains(key); } + @Override public String toString() { StringBuilder sb = new StringBuilder(); String del = "["; diff --git a/bundleplugin/src/main/java/aQute/bnd/osgi/Packages.java b/bundleplugin/src/main/java/aQute/bnd/osgi/Packages.java index 53a92da86df..a7f62909d68 100644 --- a/bundleplugin/src/main/java/aQute/bnd/osgi/Packages.java +++ b/bundleplugin/src/main/java/aQute/bnd/osgi/Packages.java @@ -179,6 +179,7 @@ public boolean containsBinaryName(String s) { return getByFQN(s) != null; } + @Override public String toString() { StringBuilder sb = new StringBuilder(); append(sb); @@ -219,11 +220,13 @@ public Attrs get(PackageRef packageRef, Attrs deflt) { return deflt; } + @Override @Deprecated public boolean equals(Object other) { return super.equals(other); } + @Override @Deprecated public int hashCode() { return super.hashCode(); diff --git a/bundleplugin/src/main/java/aQute/bnd/osgi/PreprocessResource.java b/bundleplugin/src/main/java/aQute/bnd/osgi/PreprocessResource.java index a1b5095c612..c1f847c3e71 100644 --- a/bundleplugin/src/main/java/aQute/bnd/osgi/PreprocessResource.java +++ b/bundleplugin/src/main/java/aQute/bnd/osgi/PreprocessResource.java @@ -13,6 +13,7 @@ public PreprocessResource(Processor processor, Resource r) { setExtra(resource.getExtra()); } + @Override protected byte[] getBytes() throws Exception { ByteArrayOutputStream bout = new ByteArrayOutputStream(2000); OutputStreamWriter osw = new OutputStreamWriter(bout, Constants.DEFAULT_CHARSET); diff --git a/bundleplugin/src/main/java/aQute/bnd/osgi/Processor.java b/bundleplugin/src/main/java/aQute/bnd/osgi/Processor.java index b153cb97303..5958a9d5aab 100755 --- a/bundleplugin/src/main/java/aQute/bnd/osgi/Processor.java +++ b/bundleplugin/src/main/java/aQute/bnd/osgi/Processor.java @@ -127,12 +127,10 @@ public SetLocation error(String string, Object... args) { try { if (p.isFailOk()) return p.warning(string, args); - else { - String s = formatArrays(string, args == null ? new Object[0] : args); - if (!p.errors.contains(s)) - p.errors.add(s); - return location(s); - } + String s = formatArrays(string, args == null ? new Object[0] : args); + if (!p.errors.contains(s)) + p.errors.add(s); + return location(s); } finally { p.signal(); @@ -160,13 +158,11 @@ public SetLocation error(String string, Throwable t, Object... args) { if (p.isFailOk()) { return p.warning(string + ": " + t, args); } - else { - p.errors.add("Exception: " + t.getMessage()); - String s = formatArrays(string, args == null ? new Object[0] : args); - if (!p.errors.contains(s)) - p.errors.add(s); - return location(s); - } + p.errors.add("Exception: " + t.getMessage()); + String s = formatArrays(string, args == null ? new Object[0] : args); + if (!p.errors.contains(s)) + p.errors.add(s); + return location(s); } finally { p.signal(); @@ -408,6 +404,7 @@ protected T customize(T plugin, Attrs map) { return plugin; } + @Override public boolean isFailOk() { String v = getProperty(Analyzer.FAIL_OK, null); return v != null && v.equalsIgnoreCase("true"); @@ -1184,6 +1181,7 @@ void add(URL url) { super.addURL(url); } + @Override public Class< ? > loadClass(String name) throws NoClassDefFoundError { try { Class< ? > c = super.loadClass(name); @@ -1581,6 +1579,7 @@ public Set keySet() { * Printout of the status of this processor for toString() */ + @Override public String toString() { try { StringBuilder sb = new StringBuilder(); diff --git a/bundleplugin/src/main/java/aQute/bnd/osgi/URLResource.java b/bundleplugin/src/main/java/aQute/bnd/osgi/URLResource.java index 2cd2375cdb0..5d470675408 100755 --- a/bundleplugin/src/main/java/aQute/bnd/osgi/URLResource.java +++ b/bundleplugin/src/main/java/aQute/bnd/osgi/URLResource.java @@ -18,6 +18,7 @@ public InputStream openInputStream() throws IOException { return url.openStream(); } + @Override public String toString() { return ":" + url.getPath() + ":"; } diff --git a/bundleplugin/src/main/java/aQute/bnd/osgi/Verifier.java b/bundleplugin/src/main/java/aQute/bnd/osgi/Verifier.java index eac2f6ff187..b5bd72ca4f9 100755 --- a/bundleplugin/src/main/java/aQute/bnd/osgi/Verifier.java +++ b/bundleplugin/src/main/java/aQute/bnd/osgi/Verifier.java @@ -47,6 +47,7 @@ static class EE { this.target = target; } + @Override public String toString() { return name + "(" + target + ")"; } @@ -814,6 +815,7 @@ private boolean verifyListHeader(String name, Pattern regex, boolean error) { return true; } + @Override public String getProperty(String key, String deflt) { if (properties == null) return deflt; diff --git a/bundleplugin/src/main/java/aQute/bnd/osgi/WriteResource.java b/bundleplugin/src/main/java/aQute/bnd/osgi/WriteResource.java index 494c678ec1b..ed72c41e5a7 100644 --- a/bundleplugin/src/main/java/aQute/bnd/osgi/WriteResource.java +++ b/bundleplugin/src/main/java/aQute/bnd/osgi/WriteResource.java @@ -10,6 +10,7 @@ public InputStream openInputStream() throws Exception { PipedInputStream pin = new PipedInputStream(); final PipedOutputStream pout = new PipedOutputStream(pin); Thread t = new Thread() { + @Override public void run() { try { write(pout); diff --git a/bundleplugin/src/main/java/aQute/bnd/osgi/ZipResource.java b/bundleplugin/src/main/java/aQute/bnd/osgi/ZipResource.java index edf6a686b7c..11019453577 100755 --- a/bundleplugin/src/main/java/aQute/bnd/osgi/ZipResource.java +++ b/bundleplugin/src/main/java/aQute/bnd/osgi/ZipResource.java @@ -24,6 +24,7 @@ public InputStream openInputStream() throws IOException { return zip.getInputStream(entry); } + @Override public String toString() { return ":" + zip.getName() + "(" + entry.getName() + "):"; } diff --git a/bundleplugin/src/main/java/aQute/bnd/osgi/resource/Filters.java b/bundleplugin/src/main/java/aQute/bnd/osgi/resource/Filters.java index b8c7836a958..f12e7c807ae 100644 --- a/bundleplugin/src/main/java/aQute/bnd/osgi/resource/Filters.java +++ b/bundleplugin/src/main/java/aQute/bnd/osgi/resource/Filters.java @@ -2,7 +2,6 @@ import org.osgi.framework.namespace.*; -import aQute.bnd.osgi.*; import aQute.bnd.version.*; import aQute.libg.filters.*; diff --git a/bundleplugin/src/main/java/aQute/bnd/repo/eclipse/EclipseRepo.java b/bundleplugin/src/main/java/aQute/bnd/repo/eclipse/EclipseRepo.java index e40d179e526..d7817ad9951 100644 --- a/bundleplugin/src/main/java/aQute/bnd/repo/eclipse/EclipseRepo.java +++ b/bundleplugin/src/main/java/aQute/bnd/repo/eclipse/EclipseRepo.java @@ -85,7 +85,10 @@ private String read(File index) throws Exception { private void write(File index, Map> map) throws Exception { String s = Processor.printClauses(map); - index.getParentFile().mkdirs(); + File ip = index.getParentFile(); + if (!ip.exists() && !ip.mkdirs()) { + throw new IOException("Could not create directory " + ip); + } PrintWriter fw = IO.writer(index); try { fw.write(s); @@ -166,7 +169,7 @@ public List list(String regex) { return result; } - public File put(Jar jar) throws Exception { + public PutResult put(InputStream stream, PutOptions options) throws Exception { return null; } diff --git a/bundleplugin/src/main/java/aQute/bnd/service/Deploy.java b/bundleplugin/src/main/java/aQute/bnd/service/Deploy.java index a8fc57761b9..fbdac788dd1 100644 --- a/bundleplugin/src/main/java/aQute/bnd/service/Deploy.java +++ b/bundleplugin/src/main/java/aQute/bnd/service/Deploy.java @@ -1,11 +1,12 @@ package aQute.bnd.service; +import java.io.InputStream; + import aQute.bnd.build.*; -import aQute.bnd.osgi.*; /** * Deploy this artifact to maven. */ public interface Deploy { - boolean deploy(Project project, Jar jar) throws Exception; + boolean deploy(Project project, String jarName, InputStream jarStream) throws Exception; } diff --git a/bundleplugin/src/main/java/aQute/bnd/service/RepositoryPlugin.java b/bundleplugin/src/main/java/aQute/bnd/service/RepositoryPlugin.java index 772803d8b16..73847f7d0e5 100644 --- a/bundleplugin/src/main/java/aQute/bnd/service/RepositoryPlugin.java +++ b/bundleplugin/src/main/java/aQute/bnd/service/RepositoryPlugin.java @@ -1,9 +1,9 @@ package aQute.bnd.service; import java.io.*; +import java.net.*; import java.util.*; -import aQute.bnd.osgi.*; import aQute.bnd.version.*; public interface RepositoryPlugin { @@ -11,6 +11,83 @@ public enum Strategy { LOWEST, HIGHEST, EXACT } + /** + * Options used to steer the put operation + */ + public class PutOptions { + /** + * The SHA1 digest of the artifact to put into the repository.
+ *
+ * When specified the digest of the fetched artifact will be + * calculated and verified against this digest, before putting + * the artifact into the repository.
+ *
+ * An exception is thrown if the specified digest and the calculated + * digest do not match. + */ + public byte[] digest = null; + + /** + * Allow the implementation to change the artifact.
+ *
+ * When set to true the implementation is allowed to change the artifact + * when putting it into the repository.
+ *
+ * An exception is thrown when set to false and the implementation can't + * put the artifact into the repository without changing it. + */ + public boolean allowArtifactChange = false; + + /** + * Generate a SHA1 digest.
+ *
+ * When set to true the implementation generates a digest of the + * artifact as it is put into the repository and returns that digest in + * the result. + */ + public boolean generateDigest = false; + + /** + * Create a 'latest' artifact when it did not exist.
+ *
+ * When set to true the implementation is requested to create a 'latest' + * artifact. + */ + public boolean createLatest = false; + } + + /** + * Results returned by the put operation + */ + public class PutResult { + /** + * The artifact as it was put in the repository.
+ *
+ * This can be a URI to the artifact (when it was put into the + * repository), or null when the artifact was not put into the + * repository (for example because it was already in the repository). + */ + public URI artifact = null; + + /** + * The 'latest' artifact as it was put in the repository.
+ *
+ * Only set when {@link PutOptions#createLatest} was set to true and the + * 'latest' artifact did not exist, or when the 'latest' artifact did + * exists and was older than the artifact being put in the repository. + */ + public URI latest = null; + + /** + * The SHA1 digest of the artifact as it was put into the + * repository.
+ *
+ * This will be null when {@link PutOptions#generateDigest} was null, or + * when {@link #artifact} is null. + */ + public byte[] digest = null; + } + /** * Return a URL to a matching version of the given bundle. * @@ -36,12 +113,29 @@ public enum Strategy { boolean canWrite(); /** - * Put a JAR file in the repository. + * Put an artifact (from the InputStream) into the repository.
+ *
+ * There is NO guarantee that the artifact on the input stream has not been + * modified after it's been put in the repository since that is dependent on + * the implementation of the repository (see + * {@link RepositoryPlugin.PutOptions#allowArtifactChange}). * - * @param jar + * @param stream + * The input stream with the artifact + * @param options + * The put options. See {@link RepositoryPlugin.PutOptions} + * @return The result of the put, never null. See + * {@link RepositoryPlugin.PutResult} * @throws Exception + * When the repository root directory doesn't exist, when the + * repository is read-only, when the specified checksum doesn't + * match the checksum of the fetched artifact (see + * {@link RepositoryPlugin.PutOptions#digest}), when the + * implementation wants to modify the artifact but isn't allowed + * (see {@link RepositoryPlugin.PutOptions#allowArtifactChange} + * ), or when another error has occurred. */ - File put(Jar jar) throws Exception; + PutResult put(InputStream stream, PutOptions options) throws Exception; /** * Return a list of bsns that are present in the repository. diff --git a/bundleplugin/src/main/java/aQute/bnd/service/packageinfo b/bundleplugin/src/main/java/aQute/bnd/service/packageinfo index 084a0d4e363..63eb2361213 100644 --- a/bundleplugin/src/main/java/aQute/bnd/service/packageinfo +++ b/bundleplugin/src/main/java/aQute/bnd/service/packageinfo @@ -1 +1 @@ -version 2.0.0 +version 3.0.0 diff --git a/bundleplugin/src/main/java/aQute/bnd/service/repository/MinimalRepository.java b/bundleplugin/src/main/java/aQute/bnd/service/repository/MinimalRepository.java index bbc0593151f..dab3b0cd468 100644 --- a/bundleplugin/src/main/java/aQute/bnd/service/repository/MinimalRepository.java +++ b/bundleplugin/src/main/java/aQute/bnd/service/repository/MinimalRepository.java @@ -10,7 +10,7 @@ public interface MinimalRepository { public enum Gestalt { ADD, REMOTE - }; + } Report add(File f) throws Exception; diff --git a/bundleplugin/src/main/java/aQute/bnd/signing/JartoolSigner.java b/bundleplugin/src/main/java/aQute/bnd/signing/JartoolSigner.java index fe317b8a065..f87845054fb 100644 --- a/bundleplugin/src/main/java/aQute/bnd/signing/JartoolSigner.java +++ b/bundleplugin/src/main/java/aQute/bnd/signing/JartoolSigner.java @@ -119,6 +119,7 @@ StringBuilder collect(final InputStream in) throws Exception { final StringBuilder sb = new StringBuilder(); Thread tin = new Thread() { + @Override public void run() { try { BufferedReader rdr = new BufferedReader(new InputStreamReader(in, Constants.DEFAULT_CHARSET)); diff --git a/bundleplugin/src/main/java/aQute/bnd/version/Version.java b/bundleplugin/src/main/java/aQute/bnd/version/Version.java index 359a66dcaa5..7ec3ba103ee 100755 --- a/bundleplugin/src/main/java/aQute/bnd/version/Version.java +++ b/bundleplugin/src/main/java/aQute/bnd/version/Version.java @@ -106,6 +106,7 @@ public int compareTo(Version other) { return qualifier.compareTo(o.qualifier); } + @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append(major); @@ -120,6 +121,7 @@ public String toString() { return sb.toString(); } + @Override public boolean equals(Object ot) { if (!(ot instanceof Version)) return false; @@ -127,6 +129,7 @@ public boolean equals(Object ot) { return compareTo((Version) ot) == 0; } + @Override public int hashCode() { return major * 97 ^ minor * 13 ^ micro + (qualifier == null ? 97 : qualifier.hashCode()); } diff --git a/bundleplugin/src/main/java/aQute/bnd/version/VersionRange.java b/bundleplugin/src/main/java/aQute/bnd/version/VersionRange.java index 07616167dc9..8c9a8ddbe76 100755 --- a/bundleplugin/src/main/java/aQute/bnd/version/VersionRange.java +++ b/bundleplugin/src/main/java/aQute/bnd/version/VersionRange.java @@ -41,6 +41,7 @@ public boolean includeHigh() { return end == ']'; } + @Override public String toString() { if (high == low) return high.toString(); diff --git a/bundleplugin/src/main/java/aQute/lib/base64/Base64.java b/bundleplugin/src/main/java/aQute/lib/base64/Base64.java index 777ac911f2e..33f0a8a801d 100755 --- a/bundleplugin/src/main/java/aQute/lib/base64/Base64.java +++ b/bundleplugin/src/main/java/aQute/lib/base64/Base64.java @@ -98,6 +98,7 @@ public Base64(String s) { data = decodeBase64(s); } + @Override public String toString() { return encodeBase64(data); } diff --git a/bundleplugin/src/main/java/aQute/lib/collections/SortedList.java b/bundleplugin/src/main/java/aQute/lib/collections/SortedList.java index 0747fa38fbf..4c475f112cc 100644 --- a/bundleplugin/src/main/java/aQute/lib/collections/SortedList.java +++ b/bundleplugin/src/main/java/aQute/lib/collections/SortedList.java @@ -364,11 +364,13 @@ public SortedList subList(int fromIndex, int toIndex) { return new SortedList(this, fromIndex, toIndex); } + @Override @Deprecated public boolean equals(Object other) { return super.equals(other); } + @Override @Deprecated public int hashCode() { return super.hashCode(); @@ -393,6 +395,7 @@ public void setType(Class< ? > type) { this.type = type; } + @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("["); diff --git a/bundleplugin/src/main/java/aQute/lib/deployer/FileInstallRepo.java b/bundleplugin/src/main/java/aQute/lib/deployer/FileInstallRepo.java index 75ffd7ab2ce..6bb33b6b9d2 100644 --- a/bundleplugin/src/main/java/aQute/lib/deployer/FileInstallRepo.java +++ b/bundleplugin/src/main/java/aQute/lib/deployer/FileInstallRepo.java @@ -8,6 +8,7 @@ import aQute.bnd.header.*; import aQute.bnd.osgi.*; import aQute.bnd.version.*; +import aQute.lib.io.*; import aQute.service.reporter.*; public class FileInstallRepo extends FileRepo { @@ -17,63 +18,107 @@ public class FileInstallRepo extends FileRepo { Reporter reporter; Pattern REPO_FILE = Pattern.compile("([-a-zA-z0-9_\\.]+)-([0-9\\.]+)\\.(jar|lib)"); + @Override public void setProperties(Map map) { super.setProperties(map); group = map.get("group"); } + @Override public void setReporter(Reporter reporter) { super.setReporter(reporter); this.reporter = reporter; } - public File put(Jar jar) throws Exception { - dirty = true; - Manifest manifest = jar.getManifest(); - if (manifest == null) - throw new IllegalArgumentException("No manifest in JAR: " + jar); + @Override + protected PutResult putArtifact(File tmpFile, PutOptions options) throws Exception { + assert (tmpFile != null); + assert (options != null); - String bsn = manifest.getMainAttributes().getValue(Analyzer.BUNDLE_SYMBOLICNAME); - if (bsn == null) - throw new IllegalArgumentException("No Bundle SymbolicName set"); + Jar jar = null; + try { + init(); + dirty = true; - Parameters b = Processor.parseHeader(bsn, null); - if (b.size() != 1) - throw new IllegalArgumentException("Multiple bsn's specified " + b); + jar = new Jar(tmpFile); - for (String key : b.keySet()) { - bsn = key; - if (!Verifier.SYMBOLICNAME.matcher(bsn).matches()) - throw new IllegalArgumentException("Bundle SymbolicName has wrong format: " + bsn); - } + Manifest manifest = jar.getManifest(); + if (manifest == null) + throw new IllegalArgumentException("No manifest in JAR: " + jar); - String versionString = manifest.getMainAttributes().getValue(Analyzer.BUNDLE_VERSION); - Version version; - if (versionString == null) - version = new Version(); - else - version = new Version(versionString); - - File dir; - if (group == null) { - dir = getRoot(); - } else { - dir = new File(getRoot(), group); - dir.mkdirs(); - } - String fName = bsn + "-" + version.getMajor() + "." + version.getMinor() + "." + version.getMicro() + ".jar"; - File file = new File(dir, fName); + String bsn = manifest.getMainAttributes().getValue(Analyzer.BUNDLE_SYMBOLICNAME); + if (bsn == null) + throw new IllegalArgumentException("No Bundle SymbolicName set"); - jar.write(file); - fireBundleAdded(jar, file); + Parameters b = Processor.parseHeader(bsn, null); + if (b.size() != 1) + throw new IllegalArgumentException("Multiple bsn's specified " + b); + + for (String key : b.keySet()) { + bsn = key; + if (!Verifier.SYMBOLICNAME.matcher(bsn).matches()) + throw new IllegalArgumentException("Bundle SymbolicName has wrong format: " + bsn); + } + + String versionString = manifest.getMainAttributes().getValue(Analyzer.BUNDLE_VERSION); + Version version; + if (versionString == null) + version = new Version(); + else + version = new Version(versionString); + + if (reporter != null) + reporter.trace("bsn=%s version=%s", bsn, version); + + File dir; + if (group == null) { + dir = getRoot(); + } else { + dir = new File(getRoot(), group); + if (!dir.exists() && !dir.mkdirs()) { + throw new IOException("Could not create directory " + dir); + } + } + String fName = bsn + "-" + version.getWithoutQualifier() + ".jar"; + File file = new File(dir, fName); - file = new File(dir, bsn + "-latest.jar"); - if (file.isFile() && file.lastModified() < jar.lastModified()) { - jar.write(file); + PutResult result = new PutResult(); + + if (reporter != null) + reporter.trace("updating %s ", file.getAbsolutePath()); + + if (file.exists()) { + IO.delete(file); + } + IO.rename(tmpFile, file); + result.artifact = file.toURI(); + + if (reporter != null) + reporter.progress(-1, "updated " + file.getAbsolutePath()); + + fireBundleAdded(jar, file); + + File latest = new File(dir, bsn + "-latest.jar"); + boolean latestExists = latest.exists() && latest.isFile(); + boolean latestIsOlder = latestExists && (latest.lastModified() < jar.lastModified()); + if ((options.createLatest && !latestExists) || latestIsOlder) { + if (latestExists) { + IO.delete(latest); + } + IO.copy(file, latest); + result.latest = latest.toURI(); + } + + return result; + } + finally { + if (jar != null) { + jar.close(); + } } - return file; } + @Override public boolean refresh() { if (dirty) { dirty = false; diff --git a/bundleplugin/src/main/java/aQute/lib/deployer/FileRepo.java b/bundleplugin/src/main/java/aQute/lib/deployer/FileRepo.java index 922b39c338c..2256f63e8d0 100644 --- a/bundleplugin/src/main/java/aQute/lib/deployer/FileRepo.java +++ b/bundleplugin/src/main/java/aQute/lib/deployer/FileRepo.java @@ -1,6 +1,7 @@ package aQute.lib.deployer; import java.io.*; +import java.security.*; import java.util.*; import java.util.jar.*; import java.util.regex.*; @@ -118,64 +119,175 @@ public boolean canWrite() { return canWrite; } - public File put(Jar jar) throws Exception { - init(); - dirty = true; + protected PutResult putArtifact(File tmpFile, PutOptions options) throws Exception { + assert (tmpFile != null); + assert (options != null); - Manifest manifest = jar.getManifest(); - if (manifest == null) - throw new IllegalArgumentException("No manifest in JAR: " + jar); + Jar jar = null; + try { + init(); + dirty = true; - String bsn = manifest.getMainAttributes().getValue(Analyzer.BUNDLE_SYMBOLICNAME); - if (bsn == null) - throw new IllegalArgumentException("No Bundle SymbolicName set"); + jar = new Jar(tmpFile); - Parameters b = Processor.parseHeader(bsn, null); - if (b.size() != 1) - throw new IllegalArgumentException("Multiple bsn's specified " + b); + Manifest manifest = jar.getManifest(); + if (manifest == null) + throw new IllegalArgumentException("No manifest in JAR: " + jar); - for (String key : b.keySet()) { - bsn = key; - if (!Verifier.SYMBOLICNAME.matcher(bsn).matches()) - throw new IllegalArgumentException("Bundle SymbolicName has wrong format: " + bsn); - } + String bsn = manifest.getMainAttributes().getValue(Analyzer.BUNDLE_SYMBOLICNAME); + if (bsn == null) + throw new IllegalArgumentException("No Bundle SymbolicName set"); - String versionString = manifest.getMainAttributes().getValue(Analyzer.BUNDLE_VERSION); - Version version; - if (versionString == null) - version = new Version(); - else - version = new Version(versionString); + Parameters b = Processor.parseHeader(bsn, null); + if (b.size() != 1) + throw new IllegalArgumentException("Multiple bsn's specified " + b); - if (reporter != null) - reporter.trace("bsn=%s version=%s", bsn, version); + for (String key : b.keySet()) { + bsn = key; + if (!Verifier.SYMBOLICNAME.matcher(bsn).matches()) + throw new IllegalArgumentException("Bundle SymbolicName has wrong format: " + bsn); + } + + String versionString = manifest.getMainAttributes().getValue(Analyzer.BUNDLE_VERSION); + Version version; + if (versionString == null) + version = new Version(); + else + version = new Version(versionString); - File dir = new File(root, bsn); - dir.mkdirs(); - String fName = bsn + "-" + version.getWithoutQualifier() + ".jar"; - File file = new File(dir, fName); - - if (reporter != null) - reporter.trace("updating %s ", file.getAbsolutePath()); - if (!file.exists() || file.lastModified() < jar.lastModified()) { - jar.write(file); if (reporter != null) - reporter.progress(-1, "updated " + file.getAbsolutePath()); - fireBundleAdded(jar, file); - } else { - if (reporter != null) { - reporter.progress(-1, "Did not update " + jar + " because repo has a newer version"); - reporter.trace("NOT Updating " + fName + " (repo is newer)"); + reporter.trace("bsn=%s version=%s", bsn, version); + + File dir = new File(root, bsn); + if (!dir.exists() && !dir.mkdirs()) { + throw new IOException("Could not create directory " + dir); + } + String fName = bsn + "-" + version.getWithoutQualifier() + ".jar"; + File file = new File(dir, fName); + + boolean renamed = false; + PutResult result = new PutResult(); + + if (reporter != null) + reporter.trace("updating %s ", file.getAbsolutePath()); + if (!file.exists() || file.lastModified() < jar.lastModified()) { + if (file.exists()) { + IO.delete(file); + } + IO.rename(tmpFile, file); + renamed = true; + result.artifact = file.toURI(); + + if (reporter != null) + reporter.progress(-1, "updated " + file.getAbsolutePath()); + + fireBundleAdded(jar, file); + } else { + if (reporter != null) { + reporter.progress(-1, "Did not update " + jar + " because repo has a newer version"); + reporter.trace("NOT Updating " + fName + " (repo is newer)"); + } + } + + File latest = new File(dir, bsn + "-latest.jar"); + boolean latestExists = latest.exists() && latest.isFile(); + boolean latestIsOlder = latestExists && (latest.lastModified() < jar.lastModified()); + if ((options.createLatest && !latestExists) || latestIsOlder) { + if (latestExists) { + IO.delete(latest); + } + if (!renamed) { + IO.rename(tmpFile, latest); + } else { + IO.copy(file, latest); + } + result.latest = latest.toURI(); } + + return result; + } + finally { + if (jar != null) { + jar.close(); + } + } + } + + /* a straight copy of this method lives in LocalIndexedRepo */ + public PutResult put(InputStream stream, PutOptions options) throws Exception { + /* both parameters are required */ + if ((stream == null) || (options == null)) { + throw new IllegalArgumentException("No stream and/or options specified"); + } + + /* determine if the put is allowed */ + if (!canWrite) { + throw new IOException("Repository is read-only"); } - File latest = new File(dir, bsn + "-latest.jar"); - if (latest.exists() && latest.lastModified() < jar.lastModified()) { - jar.write(latest); - file = latest; + /* the root directory of the repository has to be a directory */ + if (!root.isDirectory()) { + throw new IOException("Repository directory " + root + " is not a directory"); } - return file; + /* determine if the artifact needs to be verified */ + boolean verifyFetch = (options.digest != null); + boolean verifyPut = !options.allowArtifactChange; + + /* determine which digests are needed */ + boolean needFetchDigest = verifyFetch || verifyPut; + boolean needPutDigest = verifyPut || options.generateDigest; + + /* + * setup a new stream that encapsulates the stream and calculates (when + * needed) the digest + */ + DigestInputStream dis = new DigestInputStream(stream, MessageDigest.getInstance("SHA-1")); + dis.on(needFetchDigest); + + File tmpFile = null; + try { + /* + * copy the artifact from the (new/digest) stream into a temporary + * file in the root directory of the repository + */ + tmpFile = IO.createTempFile(root, "put", ".bnd"); + IO.copy(dis, tmpFile); + + /* get the digest if available */ + byte[] disDigest = needFetchDigest ? dis.getMessageDigest().digest() : null; + + /* verify the digest when requested */ + if (verifyFetch && !MessageDigest.isEqual(options.digest, disDigest)) { + throw new IOException("Retrieved artifact digest doesn't match specified digest"); + } + + /* put the artifact into the repository (from the temporary file) */ + PutResult r = putArtifact(tmpFile, options); + + /* calculate the digest when requested */ + if (needPutDigest && (r.artifact != null)) { + MessageDigest sha1 = MessageDigest.getInstance("SHA-1"); + IO.copy(new File(r.artifact), sha1); + r.digest = sha1.digest(); + } + + /* verify the artifact when requested */ + if (verifyPut && (r.digest != null) && !MessageDigest.isEqual(disDigest, r.digest)) { + File f = new File(r.artifact); + if (f.exists()) { + IO.delete(f); + } + throw new IOException("Stored artifact digest doesn't match specified digest"); + } + + return r; + } + finally { + if (tmpFile != null && tmpFile.exists()) { + IO.delete(tmpFile); + } + } } protected void fireBundleAdded(Jar jar, File file) { @@ -252,6 +364,7 @@ public List versions(String bsn) throws Exception { return null; } + @Override public String toString() { return String.format("%-40s r/w=%s", root.getAbsolutePath(), canWrite()); } diff --git a/bundleplugin/src/main/java/aQute/lib/filter/Filter.java b/bundleplugin/src/main/java/aQute/lib/filter/Filter.java index 853f6174bfe..2c4dd09d49f 100755 --- a/bundleplugin/src/main/java/aQute/lib/filter/Filter.java +++ b/bundleplugin/src/main/java/aQute/lib/filter/Filter.java @@ -234,6 +234,7 @@ class DictQuery extends Query { this.dict = dict; } + @Override Object getProp(String key) { return dict.get(key); } @@ -265,14 +266,17 @@ public String verify() { return null; } + @Override public String toString() { return filter; } + @Override public boolean equals(Object obj) { return obj != null && obj instanceof Filter && filter.equals(((Filter) obj).filter); } + @Override public int hashCode() { return filter.hashCode(); } diff --git a/bundleplugin/src/main/java/aQute/lib/index/Index.java b/bundleplugin/src/main/java/aQute/lib/index/Index.java index 02bb37ca422..c51286ff1ee 100644 --- a/bundleplugin/src/main/java/aQute/lib/index/Index.java +++ b/bundleplugin/src/main/java/aQute/lib/index/Index.java @@ -241,6 +241,7 @@ void insertNonFull(byte[] k, long v) throws IOException { write(); } + @Override public String toString() { StringBuilder sb = new StringBuilder(); try { @@ -334,6 +335,7 @@ Page getPage(int number) throws IOException { return page; } + @Override public String toString() { return root.toString(); } diff --git a/bundleplugin/src/main/java/aQute/lib/io/IO.java b/bundleplugin/src/main/java/aQute/lib/io/IO.java index 616dfa41289..f8a99da352a 100644 --- a/bundleplugin/src/main/java/aQute/lib/io/IO.java +++ b/bundleplugin/src/main/java/aQute/lib/io/IO.java @@ -152,7 +152,9 @@ public static void copy(File a, File b) throws IOException { out.close(); } } else if (a.isDirectory()) { - b.mkdirs(); + if (!b.exists() && !b.mkdirs()) { + throw new IOException("Could not create directory " + b); + } if (!b.isDirectory()) throw new IllegalArgumentException("target directory for a directory must be a directory: " + b); File subs[] = a.listFiles(); diff --git a/bundleplugin/src/main/java/aQute/lib/json/ByteArrayHandler.java b/bundleplugin/src/main/java/aQute/lib/json/ByteArrayHandler.java index 957369fa1a9..a336e97283b 100644 --- a/bundleplugin/src/main/java/aQute/lib/json/ByteArrayHandler.java +++ b/bundleplugin/src/main/java/aQute/lib/json/ByteArrayHandler.java @@ -33,7 +33,6 @@ Object decodeArray(Decoder r) throws Exception { Object decode(Decoder dec, String s) throws Exception { if ( dec.codec.isHex()) return Hex.toByteArray(s); - else - return Base64.decodeBase64(s); + return Base64.decodeBase64(s); } } diff --git a/bundleplugin/src/main/java/aQute/lib/json/Encoder.java b/bundleplugin/src/main/java/aQute/lib/json/Encoder.java index 0808de3879c..034ea6af75e 100644 --- a/bundleplugin/src/main/java/aQute/lib/json/Encoder.java +++ b/bundleplugin/src/main/java/aQute/lib/json/Encoder.java @@ -92,6 +92,7 @@ public Appendable append(CharSequence sq, int start, int length) throws IOExcept return this; } + @Override public String toString() { return app.toString(); } diff --git a/bundleplugin/src/main/java/aQute/lib/json/StringHandler.java b/bundleplugin/src/main/java/aQute/lib/json/StringHandler.java index ba62a136158..47a4eabb579 100644 --- a/bundleplugin/src/main/java/aQute/lib/json/StringHandler.java +++ b/bundleplugin/src/main/java/aQute/lib/json/StringHandler.java @@ -83,6 +83,7 @@ Object decode(Decoder dec ) { * An object can be assigned to a string. This means that the stream is * interpreted as the object but stored in its complete in the string. */ + @Override Object decodeObject(Decoder r) throws Exception { return collect(r, '}'); } diff --git a/bundleplugin/src/main/java/aQute/lib/spring/JPAComponent.java b/bundleplugin/src/main/java/aQute/lib/spring/JPAComponent.java index 2f08e10b097..fc219c1f927 100644 --- a/bundleplugin/src/main/java/aQute/lib/spring/JPAComponent.java +++ b/bundleplugin/src/main/java/aQute/lib/spring/JPAComponent.java @@ -14,6 +14,7 @@ */ public class JPAComponent extends XMLTypeProcessor { + @Override protected List getTypes(Analyzer analyzer) throws Exception { List types = new ArrayList(); process(types, "jpa.xsl", "META-INF", "persistence.xml"); diff --git a/bundleplugin/src/main/java/aQute/lib/spring/SpringXMLType.java b/bundleplugin/src/main/java/aQute/lib/spring/SpringXMLType.java index ae524d371eb..5ec76b02bc4 100644 --- a/bundleplugin/src/main/java/aQute/lib/spring/SpringXMLType.java +++ b/bundleplugin/src/main/java/aQute/lib/spring/SpringXMLType.java @@ -14,6 +14,7 @@ */ public class SpringXMLType extends XMLTypeProcessor { + @Override protected List getTypes(Analyzer analyzer) throws Exception { List types = new ArrayList(); diff --git a/bundleplugin/src/main/java/aQute/lib/tag/Tag.java b/bundleplugin/src/main/java/aQute/lib/tag/Tag.java index cf8668edcc0..cc305d86219 100755 --- a/bundleplugin/src/main/java/aQute/lib/tag/Tag.java +++ b/bundleplugin/src/main/java/aQute/lib/tag/Tag.java @@ -154,6 +154,7 @@ public List getContents() { * Return a string representation of this Tag and all its children * recursively. */ + @Override public String toString() { StringWriter sw = new StringWriter(); print(0, new PrintWriter(sw)); diff --git a/bundleplugin/src/main/java/aQute/libg/cafs/CAFS.java b/bundleplugin/src/main/java/aQute/libg/cafs/CAFS.java index b97babc9513..c89c5f2fed0 100644 --- a/bundleplugin/src/main/java/aQute/libg/cafs/CAFS.java +++ b/bundleplugin/src/main/java/aQute/libg/cafs/CAFS.java @@ -62,7 +62,12 @@ public CAFS(File home, boolean create) throws Exception { this.home = home; if (!home.isDirectory()) { if (create) { - home.mkdirs(); + if (home.exists()) { + throw new IOException(home + " is not a directory"); + } + if (!home.mkdirs()) { + throw new IOException("Could not create directory " + home); + } } else throw new IllegalArgumentException("CAFS requires a directory with create=false"); } @@ -290,6 +295,7 @@ public int read(byte[] data, int offset, int length) throws IOException { return size; } + @Override public int read() throws IOException { int c = super.read(); if (c < 0) @@ -315,6 +321,7 @@ void eof() throws IOException { + calculatedSha1)); } + @Override public void close() throws IOException { eof(); super.close(); diff --git a/bundleplugin/src/main/java/aQute/libg/clauses/Selector.java b/bundleplugin/src/main/java/aQute/libg/clauses/Selector.java index 8bd998df458..50b53fa4f85 100755 --- a/bundleplugin/src/main/java/aQute/libg/clauses/Selector.java +++ b/bundleplugin/src/main/java/aQute/libg/clauses/Selector.java @@ -69,6 +69,7 @@ public static Selector getPattern(String string) { return new Selector(sb.toString(), negated); } + @Override public String toString() { return getPattern(); } diff --git a/bundleplugin/src/main/java/aQute/libg/command/Command.java b/bundleplugin/src/main/java/aQute/libg/command/Command.java index deb06c56f7d..8dd1678c6eb 100644 --- a/bundleplugin/src/main/java/aQute/libg/command/Command.java +++ b/bundleplugin/src/main/java/aQute/libg/command/Command.java @@ -68,6 +68,7 @@ public void run() { if (timeout != 0) { timer = new TimerTask() { + @Override public void run() { timedout = true; process.destroy(); @@ -89,6 +90,7 @@ public void run() { if (in != null) { if (in == System.in) { rdInThread = new Thread("Read Input Thread") { + @Override public void run() { try { while (!finished.get()) { @@ -204,6 +206,7 @@ class Collector extends Thread { setDaemon(true); } + @Override public void run() { try { int c = in.read(); @@ -255,6 +258,7 @@ public String var(String name) { return variables.get(name); } + @Override public String toString() { StringBuilder sb = new StringBuilder(); String del = ""; diff --git a/bundleplugin/src/main/java/aQute/libg/cryptography/Digest.java b/bundleplugin/src/main/java/aQute/libg/cryptography/Digest.java index aeb4bbb89a4..119a35b3842 100644 --- a/bundleplugin/src/main/java/aQute/libg/cryptography/Digest.java +++ b/bundleplugin/src/main/java/aQute/libg/cryptography/Digest.java @@ -28,6 +28,7 @@ public String toString() { public abstract String getAlgorithm(); + @Override public boolean equals(Object other) { if (!(other instanceof Digest)) return false; @@ -36,6 +37,7 @@ public boolean equals(Object other) { return Arrays.equals(d.digest, digest); } + @Override public int hashCode() { return Arrays.hashCode(digest); } diff --git a/bundleplugin/src/main/java/aQute/libg/sed/ReplacerAdapter.java b/bundleplugin/src/main/java/aQute/libg/sed/ReplacerAdapter.java index 37ef4518adf..84a0620af68 100644 --- a/bundleplugin/src/main/java/aQute/libg/sed/ReplacerAdapter.java +++ b/bundleplugin/src/main/java/aQute/libg/sed/ReplacerAdapter.java @@ -228,8 +228,7 @@ private String doCommands(String key, Link source) { Domain parent = source.start.getParent(); if (parent != null) return parent.getMap().get(varname); - else - return null; + return null; } Domain rover = domain; @@ -371,8 +370,7 @@ public String _if(String args[]) { if (args.length > 3) return args[3]; - else - return ""; + return ""; } public String _now(String args[]) { @@ -520,19 +518,18 @@ public String _dir(String args[]) { if (args.length < 2) { reporter.warning("Need at least one file name for ${dir;...}"); return null; - } else { - String del = ""; - StringBuilder sb = new StringBuilder(); - for (int i = 1; i < args.length; i++) { - File f = IO.getFile(base, args[i]); - if (f.exists() && f.getParentFile().exists()) { - sb.append(del); - sb.append(f.getParentFile().getAbsolutePath()); - del = ","; - } + } + String del = ""; + StringBuilder sb = new StringBuilder(); + for (int i = 1; i < args.length; i++) { + File f = IO.getFile(base, args[i]); + if (f.exists() && f.getParentFile().exists()) { + sb.append(del); + sb.append(f.getParentFile().getAbsolutePath()); + del = ","; } - return sb.toString(); } + return sb.toString(); } @@ -540,19 +537,18 @@ public String _basename(String args[]) { if (args.length < 2) { reporter.warning("Need at least one file name for ${basename;...}"); return null; - } else { - String del = ""; - StringBuilder sb = new StringBuilder(); - for (int i = 1; i < args.length; i++) { - File f = IO.getFile(base, args[i]); - if (f.exists() && f.getParentFile().exists()) { - sb.append(del); - sb.append(f.getName()); - del = ","; - } + } + String del = ""; + StringBuilder sb = new StringBuilder(); + for (int i = 1; i < args.length; i++) { + File f = IO.getFile(base, args[i]); + if (f.exists() && f.getParentFile().exists()) { + sb.append(del); + sb.append(f.getName()); + del = ","; } - return sb.toString(); } + return sb.toString(); } @@ -560,14 +556,13 @@ public String _isfile(String args[]) { if (args.length < 2) { reporter.warning("Need at least one file name for ${isfile;...}"); return null; - } else { - boolean isfile = true; - for (int i = 1; i < args.length; i++) { - File f = new File(args[i]).getAbsoluteFile(); - isfile &= f.isFile(); - } - return isfile ? "true" : "false"; } + boolean isfile = true; + for (int i = 1; i < args.length; i++) { + File f = new File(args[i]).getAbsoluteFile(); + isfile &= f.isFile(); + } + return isfile ? "true" : "false"; } @@ -575,14 +570,13 @@ public String _isdir(String args[]) { if (args.length < 2) { reporter.warning("Need at least one file name for ${isdir;...}"); return null; - } else { - boolean isdir = true; - for (int i = 1; i < args.length; i++) { - File f = new File(args[i]).getAbsoluteFile(); - isdir &= f.isDirectory(); - } - return isdir ? "true" : "false"; } + boolean isdir = true; + for (int i = 1; i < args.length; i++) { + File f = new File(args[i]).getAbsoluteFile(); + isdir &= f.isDirectory(); + } + return isdir ? "true" : "false"; } @@ -801,6 +795,7 @@ public boolean contains(String key) { return previous.contains(key); } + @Override public String toString() { StringBuilder sb = new StringBuilder("["); append(sb); diff --git a/bundleplugin/src/main/java/aQute/libg/tarjan/Tarjan.java b/bundleplugin/src/main/java/aQute/libg/tarjan/Tarjan.java index cef8b233bcd..c3e8ee12417 100644 --- a/bundleplugin/src/main/java/aQute/libg/tarjan/Tarjan.java +++ b/bundleplugin/src/main/java/aQute/libg/tarjan/Tarjan.java @@ -16,6 +16,7 @@ public Node(T name) { this.name = name; } + @Override public String toString() { return name + "{" + index + "," + low + "}"; }