From 28b5f5d0dad50d1c2a6e6d42df58287009796d62 Mon Sep 17 00:00:00 2001 From: Benjamin Marwell Date: Fri, 19 Feb 2021 12:35:39 +0100 Subject: [PATCH] [#194] remove guava, not used. --- pom.xml | 22 ++++---- .../java/org/reficio/p2/FeatureBuilder.java | 12 +++-- src/main/java/org/reficio/p2/P2Mojo.java | 33 +++++++----- .../org/reficio/p2/bundler/P2ArtifactMap.java | 53 +++++++++++++++++++ .../reficio/p2/publisher/BundlePublisher.java | 6 +-- .../p2/publisher/CategoryPublisher.java | 20 +++---- .../reficio/p2/bundler/P2ArtifactMapTest.java | 39 ++++++++++++++ 7 files changed, 141 insertions(+), 44 deletions(-) create mode 100644 src/main/java/org/reficio/p2/bundler/P2ArtifactMap.java create mode 100644 src/test/java/org/reficio/p2/bundler/P2ArtifactMapTest.java diff --git a/pom.xml b/pom.xml index 2d0762dc..43d1e9ca 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ UTF-8 UTF-8 - 1.7 + 1.8 ${java.version} ${java.version} @@ -135,11 +135,6 @@ - - org.apache.maven - maven-core - ${maven.version} - org.apache.maven maven-plugin-api @@ -190,11 +185,6 @@ commons-io 2.6 - - com.google.guava - guava - 21.0 - biz.aQute.bnd biz.aQute.bndlib @@ -203,6 +193,12 @@ org.twdata.maven mojo-executor 2.2.0 + + + * + * + + org.apache.felix @@ -258,7 +254,7 @@ - mojo-descriptor + default-descriptor process-classes descriptor @@ -339,7 +335,7 @@ org.codehaus.plexus plexus-component-metadata - 1.5.5 + 1.7.1 diff --git a/src/main/java/org/reficio/p2/FeatureBuilder.java b/src/main/java/org/reficio/p2/FeatureBuilder.java index 265edc52..bbc0e85e 100644 --- a/src/main/java/org/reficio/p2/FeatureBuilder.java +++ b/src/main/java/org/reficio/p2/FeatureBuilder.java @@ -27,19 +27,21 @@ import javax.xml.parsers.ParserConfigurationException; import org.reficio.p2.bundler.ArtifactBundlerInstructions; +import org.reficio.p2.bundler.P2ArtifactMap; import org.reficio.p2.logger.Logger; import org.reficio.p2.utils.JarUtils; import org.reficio.p2.utils.XmlUtils; import org.w3c.dom.Document; import org.w3c.dom.Element; -import com.google.common.collect.Multimap; - public class FeatureBuilder { - public FeatureBuilder(P2FeatureDefinition p2FeatureDefintion, Multimap bundlerInstructions, boolean generateSourceFeature, boolean unpack, String timestamp) { + public FeatureBuilder(P2FeatureDefinition p2FeatureDefintion, + final P2ArtifactMap bundlerInstructions, + boolean generateSourceFeature, + boolean unpack, + String timestamp) { this.p2FeatureDefintion = p2FeatureDefintion; this.bundlerInstructions = bundlerInstructions; this.generateSourceFeature = generateSourceFeature; @@ -47,7 +49,7 @@ public FeatureBuilder(P2FeatureDefinition p2FeatureDefintion, Multimap bundlerInstructions; + private P2ArtifactMap bundlerInstructions; private P2FeatureDefinition p2FeatureDefintion; private boolean generateSourceFeature; private boolean unpack; diff --git a/src/main/java/org/reficio/p2/P2Mojo.java b/src/main/java/org/reficio/p2/P2Mojo.java index 7d623f8f..3dc96f9d 100644 --- a/src/main/java/org/reficio/p2/P2Mojo.java +++ b/src/main/java/org/reficio/p2/P2Mojo.java @@ -18,10 +18,8 @@ */ package org.reficio.p2; -import com.google.common.base.Preconditions; import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.Multimap; -import com.google.common.collect.Sets; import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; import org.apache.maven.execution.MavenSession; @@ -43,6 +41,7 @@ import org.reficio.p2.bundler.ArtifactBundler; import org.reficio.p2.bundler.ArtifactBundlerInstructions; import org.reficio.p2.bundler.ArtifactBundlerRequest; +import org.reficio.p2.bundler.P2ArtifactMap; import org.reficio.p2.bundler.impl.AquteBundler; import org.reficio.p2.logger.Logger; import org.reficio.p2.publisher.BundlePublisher; @@ -60,9 +59,12 @@ import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; +import java.util.HashSet; import java.util.List; import java.util.Set; +import static java.util.Objects.requireNonNull; + /** * Main plugin class @@ -269,7 +271,7 @@ private void initializeRepositorySystem() { if (repoSystem == null) { repoSystem = lookup("org.sonatype.aether.RepositorySystem"); } - Preconditions.checkNotNull(repoSystem, "Could not initialize RepositorySystem"); + requireNonNull(repoSystem, "Could not initialize RepositorySystem"); } private Object lookup(String role) { @@ -280,11 +282,11 @@ private Object lookup(String role) { return null; } - private Multimap processArtifacts(List artifacts) { + private P2ArtifactMap processArtifacts(List artifacts) { BundleUtils.INSTANCE.setReuseSnapshotVersionFromArtifact(reuseSnapshotVersionFromArtifact); - Multimap bundlerInstructions = ArrayListMultimap.create(); + P2ArtifactMap bundlerInstructions = new P2ArtifactMap<>(); - Multimap resolvedArtifacts = resolveArtifacts(artifacts); + P2ArtifactMap resolvedArtifacts = resolveArtifacts(artifacts); Set processedArtifacts = processRootArtifacts(resolvedArtifacts, bundlerInstructions, artifacts); processTransitiveArtifacts(resolvedArtifacts, processedArtifacts, bundlerInstructions, artifacts); @@ -292,11 +294,12 @@ private Multimap processArtifacts(List } - private Set processRootArtifacts(Multimap processedArtifacts, - Multimap bundlerInstructions, List artifacts) { + private Set processRootArtifacts(P2ArtifactMap processedArtifacts, + P2ArtifactMap bundlerInstructions, + List artifacts) { - Set bundledArtifacts = Sets.newHashSet(); + Set bundledArtifacts = new HashSet<>(); for (P2Artifact p2Artifact : artifacts) { for (ResolvedArtifact resolvedArtifact : processedArtifacts.get(p2Artifact)) { if (resolvedArtifact.isRoot()) { @@ -315,8 +318,10 @@ private Set processRootArtifacts(Multimap resolvedArtifacts, Set bundledArtifacts, - Multimap bundlerInstructions, List artifacts) { + private void processTransitiveArtifacts(P2ArtifactMap resolvedArtifacts, + Set bundledArtifacts, + P2ArtifactMap bundlerInstructions, + List artifacts) { // then bundle transitive artifacts for (P2Artifact p2Artifact : artifacts) { @@ -361,8 +366,8 @@ private void processFeatures() { } - private Multimap resolveArtifacts(List artifacts) { - Multimap resolvedArtifacts = ArrayListMultimap.create(); + private P2ArtifactMap resolveArtifacts(List artifacts) { + P2ArtifactMap resolvedArtifacts = new P2ArtifactMap(); for (P2Artifact p2Artifact : artifacts) { logResolving(p2Artifact); ArtifactResolutionResult resolutionResult; @@ -434,7 +439,7 @@ private void logResolved(ArtifactResolutionRequest resolutionRequest, ArtifactRe private void createFeature(P2FeatureDefinition p2featureDefinition) { try { - Multimap bi = this.processArtifacts(p2featureDefinition.getArtifacts()); + P2ArtifactMap bi = this.processArtifacts(p2featureDefinition.getArtifacts()); if (null==p2featureDefinition.getFeatureFile()) { //we must be generating the feature file from the pom diff --git a/src/main/java/org/reficio/p2/bundler/P2ArtifactMap.java b/src/main/java/org/reficio/p2/bundler/P2ArtifactMap.java new file mode 100644 index 00000000..7f7316b4 --- /dev/null +++ b/src/main/java/org/reficio/p2/bundler/P2ArtifactMap.java @@ -0,0 +1,53 @@ +/** + * Copyright (c) 2012 Reficio (TM) - Reestablish your software! All Rights Reserved. + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.reficio.p2.bundler; + +import org.reficio.p2.P2Artifact; + +import java.util.*; +import java.util.concurrent.ConcurrentHashMap; + +public class P2ArtifactMap extends ConcurrentHashMap> { + + public void putAll(P2Artifact key, Collection values) { + this.replace(key, compute(key, (k, oldValues) -> newOrAdd(oldValues, values))); + } + + public void put(P2Artifact key, T value) { + this.replace(key, compute(key, (k, oldValues) -> newOrAdd(oldValues, Collections.singleton(value)))); + } + + private Collection newOrAdd(Collection oldValues, + Collection values) { + if (oldValues == null) { + return new ArrayList<>(values); + } else { + List newList = new ArrayList<>(oldValues); + newList.addAll(values); + return newList; + } + } + + @Override + public Collection get(Object key) { + return Optional.ofNullable(super.get(key)) + .orElseGet(Collections::emptyList); + } + +} diff --git a/src/main/java/org/reficio/p2/publisher/BundlePublisher.java b/src/main/java/org/reficio/p2/publisher/BundlePublisher.java index 8198462f..3d35e1e1 100644 --- a/src/main/java/org/reficio/p2/publisher/BundlePublisher.java +++ b/src/main/java/org/reficio/p2/publisher/BundlePublisher.java @@ -26,7 +26,7 @@ import java.io.IOException; -import static com.google.common.base.Preconditions.checkNotNull; +import static java.util.Objects.requireNonNull; import static org.twdata.maven.mojoexecutor.MojoExecutor.*; /** @@ -109,8 +109,8 @@ public Builder buildPluginManager(BuildPluginManager buildPluginManager) { } public BundlePublisher build() { - return new BundlePublisher(compressSite, additionalArgs, checkNotNull(mavenProject), - checkNotNull(mavenSession), checkNotNull(buildPluginManager)); + return new BundlePublisher(compressSite, additionalArgs, requireNonNull(mavenProject), + requireNonNull(mavenSession), requireNonNull(buildPluginManager)); } } } diff --git a/src/main/java/org/reficio/p2/publisher/CategoryPublisher.java b/src/main/java/org/reficio/p2/publisher/CategoryPublisher.java index a8ebd41c..b67ca068 100644 --- a/src/main/java/org/reficio/p2/publisher/CategoryPublisher.java +++ b/src/main/java/org/reficio/p2/publisher/CategoryPublisher.java @@ -27,8 +27,7 @@ import java.io.File; import java.io.IOException; -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; +import static java.util.Objects.requireNonNull; /** * @author Tom Bujok (tom.bujok@gmail.com)
@@ -94,13 +93,16 @@ public static class Builder { private String metadataRepositoryLocation; public Builder p2ApplicationLauncher(P2ApplicationLauncher launcher) { - checkNotNull(launcher, "p2ApplicationLauncher cannot be null"); + requireNonNull(launcher, "p2ApplicationLauncher cannot be null"); this.launcher = launcher; return this; } public Builder forkedProcessTimeoutInSeconds(int forkedProcessTimeoutInSeconds) { - checkArgument(forkedProcessTimeoutInSeconds >= 0, "forkedProcessTimeoutInSeconds cannot be negative"); + if (forkedProcessTimeoutInSeconds < 0) { + throw new IllegalArgumentException("forkedProcessTimeoutInSeconds cannot be negative but was: " + forkedProcessTimeoutInSeconds); + } + this.forkedProcessTimeoutInSeconds = forkedProcessTimeoutInSeconds; return this; } @@ -115,21 +117,21 @@ public Builder additionalArgs(String additionalArgs) { } public Builder categoryFileLocation(String categoryFileLocation) { - checkNotNull(categoryFileLocation, "categoryFileLocation cannot be null"); + requireNonNull(categoryFileLocation, "categoryFileLocation cannot be null"); this.categoryFileLocation = categoryFileLocation; return this; } public Builder metadataRepositoryLocation(String metadataRepositoryLocation) { - checkNotNull(metadataRepositoryLocation, "metadataRepositoryLocation cannot be null"); + requireNonNull(metadataRepositoryLocation, "metadataRepositoryLocation cannot be null"); this.metadataRepositoryLocation = metadataRepositoryLocation; return this; } public CategoryPublisher build() { - checkNotNull(launcher, "p2ApplicationLauncher cannot be null"); - checkNotNull(categoryFileLocation, "categoryFileLocation cannot be null"); - checkNotNull(metadataRepositoryLocation, "metadataRepositoryLocation cannot be null"); + requireNonNull(launcher, "p2ApplicationLauncher cannot be null"); + requireNonNull(categoryFileLocation, "categoryFileLocation cannot be null"); + requireNonNull(metadataRepositoryLocation, "metadataRepositoryLocation cannot be null"); return new CategoryPublisher(launcher, forkedProcessTimeoutInSeconds, additionalArgs, categoryFileLocation, metadataRepositoryLocation); } diff --git a/src/test/java/org/reficio/p2/bundler/P2ArtifactMapTest.java b/src/test/java/org/reficio/p2/bundler/P2ArtifactMapTest.java new file mode 100644 index 00000000..c1b74f77 --- /dev/null +++ b/src/test/java/org/reficio/p2/bundler/P2ArtifactMapTest.java @@ -0,0 +1,39 @@ +/** + * Copyright (c) 2012 Reficio (TM) - Reestablish your software! All Rights Reserved. + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.reficio.p2.bundler; + +import org.junit.Test; +import org.reficio.p2.P2Artifact; + +import java.util.Collection; + +import static org.junit.Assert.*; + +public class P2ArtifactMapTest { + + @Test + public void getNoFoundValueReturnsEmptyList() { + P2ArtifactMap mapUnderTest = new P2ArtifactMap<>(); + + Collection value = mapUnderTest.get(new P2Artifact()); + + assertNotNull(value); + } +}