Skip to content

Commit

Permalink
Merge pull request #196 from bmarwell/194-guava
Browse files Browse the repository at this point in the history
[#194] remove guava, not used.
  • Loading branch information
sparsick authored Feb 19, 2021
2 parents df26dba + 28b5f5d commit d6a88d3
Show file tree
Hide file tree
Showing 7 changed files with 141 additions and 44 deletions.
22 changes: 9 additions & 13 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.7</java.version>
<java.version>1.8</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>

Expand Down Expand Up @@ -135,11 +135,6 @@
</dependencyManagement>

<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-core</artifactId>
<version>${maven.version}</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
Expand Down Expand Up @@ -190,11 +185,6 @@
<artifactId>commons-io</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>21.0</version>
</dependency>
<dependency>
<groupId>biz.aQute.bnd</groupId>
<artifactId>biz.aQute.bndlib</artifactId>
Expand All @@ -203,6 +193,12 @@
<groupId>org.twdata.maven</groupId>
<artifactId>mojo-executor</artifactId>
<version>2.2.0</version>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.felix</groupId>
Expand Down Expand Up @@ -258,7 +254,7 @@
</configuration>
<executions>
<execution>
<id>mojo-descriptor</id>
<id>default-descriptor</id>
<phase>process-classes</phase>
<goals>
<goal>descriptor</goal>
Expand Down Expand Up @@ -339,7 +335,7 @@
<plugin>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-component-metadata</artifactId>
<version>1.5.5</version>
<version>1.7.1</version>
<executions>
<execution>
<goals>
Expand Down
12 changes: 7 additions & 5 deletions src/main/java/org/reficio/p2/FeatureBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,27 +27,29 @@
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<P2Artifact,
ArtifactBundlerInstructions> 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;
this.unpack = unpack;
this.featureTimeStamp = timestamp;
}

private Multimap<P2Artifact, ArtifactBundlerInstructions> bundlerInstructions;
private P2ArtifactMap<ArtifactBundlerInstructions> bundlerInstructions;
private P2FeatureDefinition p2FeatureDefintion;
private boolean generateSourceFeature;
private boolean unpack;
Expand Down
33 changes: 19 additions & 14 deletions src/main/java/org/reficio/p2/P2Mojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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) {
Expand All @@ -280,23 +282,24 @@ private Object lookup(String role) {
return null;
}

private Multimap<P2Artifact, ArtifactBundlerInstructions> processArtifacts(List<P2Artifact> artifacts) {
private P2ArtifactMap<ArtifactBundlerInstructions> processArtifacts(List<P2Artifact> artifacts) {
BundleUtils.INSTANCE.setReuseSnapshotVersionFromArtifact(reuseSnapshotVersionFromArtifact);
Multimap<P2Artifact, ArtifactBundlerInstructions> bundlerInstructions = ArrayListMultimap.create();
P2ArtifactMap<ArtifactBundlerInstructions> bundlerInstructions = new P2ArtifactMap<>();

Multimap<P2Artifact, ResolvedArtifact> resolvedArtifacts = resolveArtifacts(artifacts);
P2ArtifactMap<ResolvedArtifact> resolvedArtifacts = resolveArtifacts(artifacts);
Set<Artifact> processedArtifacts = processRootArtifacts(resolvedArtifacts, bundlerInstructions, artifacts);
processTransitiveArtifacts(resolvedArtifacts, processedArtifacts, bundlerInstructions, artifacts);

return bundlerInstructions;

}

private Set<Artifact> processRootArtifacts(Multimap<P2Artifact, ResolvedArtifact> processedArtifacts,
Multimap<P2Artifact, ArtifactBundlerInstructions> bundlerInstructions, List<P2Artifact> artifacts) {
private Set<Artifact> processRootArtifacts(P2ArtifactMap<ResolvedArtifact> processedArtifacts,
P2ArtifactMap<ArtifactBundlerInstructions> bundlerInstructions,
List<P2Artifact> artifacts) {


Set<Artifact> bundledArtifacts = Sets.newHashSet();
Set<Artifact> bundledArtifacts = new HashSet<>();
for (P2Artifact p2Artifact : artifacts) {
for (ResolvedArtifact resolvedArtifact : processedArtifacts.get(p2Artifact)) {
if (resolvedArtifact.isRoot()) {
Expand All @@ -315,8 +318,10 @@ private Set<Artifact> processRootArtifacts(Multimap<P2Artifact, ResolvedArtifact
return bundledArtifacts;
}

private void processTransitiveArtifacts(Multimap<P2Artifact, ResolvedArtifact> resolvedArtifacts, Set<Artifact> bundledArtifacts,
Multimap<P2Artifact, ArtifactBundlerInstructions> bundlerInstructions, List<P2Artifact> artifacts) {
private void processTransitiveArtifacts(P2ArtifactMap<ResolvedArtifact> resolvedArtifacts,
Set<Artifact> bundledArtifacts,
P2ArtifactMap<ArtifactBundlerInstructions> bundlerInstructions,
List<P2Artifact> artifacts) {
// then bundle transitive artifacts

for (P2Artifact p2Artifact : artifacts) {
Expand Down Expand Up @@ -361,8 +366,8 @@ private void processFeatures() {
}


private Multimap<P2Artifact, ResolvedArtifact> resolveArtifacts(List<P2Artifact> artifacts) {
Multimap<P2Artifact, ResolvedArtifact> resolvedArtifacts = ArrayListMultimap.create();
private P2ArtifactMap<ResolvedArtifact> resolveArtifacts(List<P2Artifact> artifacts) {
P2ArtifactMap<ResolvedArtifact> resolvedArtifacts = new P2ArtifactMap<ResolvedArtifact>();
for (P2Artifact p2Artifact : artifacts) {
logResolving(p2Artifact);
ArtifactResolutionResult resolutionResult;
Expand Down Expand Up @@ -434,7 +439,7 @@ private void logResolved(ArtifactResolutionRequest resolutionRequest, ArtifactRe

private void createFeature(P2FeatureDefinition p2featureDefinition) {
try {
Multimap<P2Artifact, ArtifactBundlerInstructions> 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
Expand Down
53 changes: 53 additions & 0 deletions src/main/java/org/reficio/p2/bundler/P2ArtifactMap.java
Original file line number Diff line number Diff line change
@@ -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<T> extends ConcurrentHashMap<P2Artifact, Collection<T>> {

public void putAll(P2Artifact key, Collection<T> 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<T> newOrAdd(Collection<T> oldValues,
Collection<T> values) {
if (oldValues == null) {
return new ArrayList<>(values);
} else {
List<T> newList = new ArrayList<>(oldValues);
newList.addAll(values);
return newList;
}
}

@Override
public Collection<T> get(Object key) {
return Optional.ofNullable(super.get(key))
.orElseGet(Collections::emptyList);
}

}
6 changes: 3 additions & 3 deletions src/main/java/org/reficio/p2/publisher/BundlePublisher.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;

/**
Expand Down Expand Up @@ -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));
}
}
}
20 changes: 11 additions & 9 deletions src/main/java/org/reficio/p2/publisher/CategoryPublisher.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)<br>
Expand Down Expand Up @@ -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;
}
Expand All @@ -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);
}
Expand Down
39 changes: 39 additions & 0 deletions src/test/java/org/reficio/p2/bundler/P2ArtifactMapTest.java
Original file line number Diff line number Diff line change
@@ -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<P2Artifact> mapUnderTest = new P2ArtifactMap<>();

Collection<P2Artifact> value = mapUnderTest.get(new P2Artifact());

assertNotNull(value);
}
}

0 comments on commit d6a88d3

Please sign in to comment.