Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,9 @@ under the License.
<artifactId>plexus-xml</artifactId>
</dependency>
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
<version>3.0.2</version>
<groupId>org.jspecify</groupId>
Comment thread
elharo marked this conversation as resolved.
<artifactId>jspecify</artifactId>
<version>1.0.0</version>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why it's not compile scope?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Compile is the default scope, used if none is specified. I added the scope to the dependency.

<scope>compile</scope>
</dependency>
<dependency>
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/org/apache/maven/buildcache/CacheContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.apache.maven.buildcache.xml.build.ProjectsInputInfo;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.project.MavenProject;
import org.jspecify.annotations.NonNull;

import static java.util.Objects.requireNonNull;

Expand All @@ -39,14 +40,17 @@ public CacheContext(MavenProject project, ProjectsInputInfo inputInfo, MavenSess
this.session = requireNonNull(session);
}

@NonNull
public MavenProject getProject() {
return project;
}

@NonNull
public ProjectsInputInfo getInputInfo() {
return inputInfo;
}

@NonNull
public MavenSession getSession() {
return session;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
*/
package org.apache.maven.buildcache;

import javax.annotation.Nonnull;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Provider;
Expand Down Expand Up @@ -94,6 +93,7 @@
import org.apache.maven.project.MavenProjectHelper;
import org.codehaus.plexus.util.ReflectionUtils;
import org.eclipse.aether.RepositorySystem;
import org.jspecify.annotations.NonNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -186,7 +186,7 @@ public CacheControllerImpl(
}

@Override
@Nonnull
@NonNull
public CacheResult findCachedBuild(
MavenSession session, MavenProject project, List<MojoExecution> mojoExecutions, boolean skipCache) {
final LifecyclePhasesHelper lifecyclePhasesHelper = providerLifecyclePhasesHelper.get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,21 @@
*/
package org.apache.maven.buildcache;

import javax.annotation.Nonnull;

import java.io.IOException;
import java.util.Optional;

import org.apache.maven.artifact.Artifact;
import org.apache.maven.buildcache.xml.Build;
import org.apache.maven.buildcache.xml.report.CacheReport;
import org.apache.maven.execution.MavenSession;
import org.jspecify.annotations.NonNull;

/**
* Cache repository.
*/
public interface CacheRepository {

@Nonnull
@NonNull
Optional<Build> findBuild(CacheContext context) throws IOException;

void saveBuildInfo(CacheResult cacheResult, Build build) throws IOException;
Expand Down
8 changes: 7 additions & 1 deletion src/main/java/org/apache/maven/buildcache/CacheResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

import org.apache.maven.buildcache.xml.Build;
import org.apache.maven.buildcache.xml.CacheSource;
import org.jspecify.annotations.NonNull;
import org.jspecify.annotations.Nullable;

import static java.util.Objects.requireNonNull;

Expand All @@ -32,7 +34,7 @@ public class CacheResult {
private final Build build;
private final CacheContext context;

private CacheResult(RestoreStatus status, Build build, CacheContext context) {
private CacheResult(RestoreStatus status, @Nullable Build build, @Nullable CacheContext context) {
this.status = requireNonNull(status);
this.build = build;
this.context = context;
Expand Down Expand Up @@ -88,14 +90,17 @@ public boolean isSuccess() {
return status == RestoreStatus.SUCCESS;
}

@Nullable
public Build getBuildInfo() {
return build;
}

@Nullable
public CacheSource getSource() {
return build != null ? build.getSource() : null;
}

@Nullable
public CacheContext getContext() {
return context;
}
Expand All @@ -104,6 +109,7 @@ public boolean isPartialSuccess() {
return status == RestoreStatus.PARTIAL;
}

@NonNull
public RestoreStatus getStatus() {
return status;
}
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/org/apache/maven/buildcache/CacheUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
import org.apache.maven.model.Dependency;
import org.apache.maven.plugin.MojoExecution;
import org.apache.maven.project.MavenProject;
import org.jspecify.annotations.Nullable;
import org.slf4j.Logger;

import static org.apache.maven.artifact.Artifact.LATEST_VERSION;
Expand All @@ -69,10 +70,11 @@ public static boolean isPom(Dependency dependency) {
return dependency.getType().equals("pom");
}

public static boolean isSnapshot(String version) {
public static boolean isSnapshot(@Nullable String version) {
return version != null && (version.endsWith(SNAPSHOT_VERSION) || version.endsWith(LATEST_VERSION));
}

@Nullable
public static String normalizedName(Artifact artifact) {
if (artifact.getFile() == null) {
return null;
Expand Down Expand Up @@ -241,7 +243,7 @@ public static void unzip(Path zip, Path out, boolean preservePermissions) throws
}

public static <T> void debugPrintCollection(
Logger logger, Collection<T> values, String heading, String elementCaption) {
Logger logger, @Nullable Collection<T> values, @Nullable String heading, @Nullable String elementCaption) {
if (logger.isDebugEnabled() && values != null && !values.isEmpty()) {
final int size = values.size();
int i = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@
*/
package org.apache.maven.buildcache;

import javax.annotation.Nonnull;

import org.apache.maven.buildcache.xml.config.DirScanConfig;
import org.jspecify.annotations.NonNull;

/**
* DefaultPluginScanConfig
Expand All @@ -38,12 +37,12 @@ public boolean accept(String propertyName) {
}

@Override
@Nonnull
@NonNull
public PluginScanConfig mergeWith(PluginScanConfig overrideSource) {
return overrideSource;
}

@Nonnull
@NonNull
@Override
public ScanConfigProperties getTagScanProperties(String tagName) {
return new ScanConfigProperties(true, "*");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
*/
package org.apache.maven.buildcache;

import javax.annotation.Nonnull;
import javax.annotation.PostConstruct;
import javax.inject.Inject;
import javax.inject.Named;
Expand All @@ -40,6 +39,7 @@
import org.apache.maven.lifecycle.Lifecycle;
import org.apache.maven.plugin.MojoExecution;
import org.apache.maven.project.MavenProject;
import org.jspecify.annotations.NonNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -103,7 +103,7 @@ public void forkedProjectFailed(ExecutionEvent event) {
forkedProjectToOrigin.remove(event.getProject(), event.getMojoExecution());
}

@Nonnull
@NonNull
public String resolveHighestLifecyclePhase(MavenProject project, List<MojoExecution> mojoExecutions) {
return resolveMojoExecutionLifecyclePhase(project, CacheUtils.getLast(mojoExecutions));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
*/
package org.apache.maven.buildcache;

import javax.annotation.Nonnull;

import java.io.IOException;
import java.nio.file.Path;
import java.util.Optional;
Expand All @@ -29,6 +27,7 @@
import org.apache.maven.buildcache.xml.build.Artifact;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.model.Dependency;
import org.jspecify.annotations.NonNull;

/**
* Local cache repository.
Expand All @@ -41,9 +40,9 @@ public interface LocalCacheRepository extends CacheRepository {

void clearCache(CacheContext context);

@Nonnull
@NonNull
Optional<Build> findBestMatchingBuild(MavenSession session, Dependency dependency) throws IOException;

@Nonnull
@NonNull
Optional<Build> findLocalBuild(CacheContext context) throws IOException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
*/
package org.apache.maven.buildcache;

import javax.annotation.Nonnull;
import javax.inject.Inject;
import javax.inject.Named;

Expand Down Expand Up @@ -57,6 +56,7 @@
import org.apache.maven.execution.MavenSession;
import org.apache.maven.model.Dependency;
import org.apache.maven.project.MavenProject;
import org.jspecify.annotations.NonNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -100,7 +100,7 @@ public LocalCacheRepositoryImpl(
this.cacheConfig = cacheConfig;
}

@Nonnull
@NonNull
@Override
public Optional<Build> findLocalBuild(CacheContext context) throws IOException {
Path localBuildInfoPath = localBuildPath(context, BUILDINFO_XML, false);
Expand All @@ -119,7 +119,7 @@ public Optional<Build> findLocalBuild(CacheContext context) throws IOException {
return Optional.empty();
}

@Nonnull
@NonNull
@Override
public Optional<Build> findBuild(CacheContext context) throws IOException {
Path buildInfoPath = remoteBuildPath(context, BUILDINFO_XML);
Expand Down Expand Up @@ -218,13 +218,13 @@ public void clearCache(CacheContext context) {
}
}

@Nonnull
@NonNull
@Override
public Optional<Build> findBestMatchingBuild(MavenSession session, Dependency dependency) {
return bestBuildCache.computeIfAbsent(Pair.of(session, dependency), this::findBestMatchingBuildImpl);
}

@Nonnull
@NonNull
private Optional<Build> findBestMatchingBuildImpl(Pair<MavenSession, Dependency> dependencySession) {
try {
final MavenSession session = dependencySession.getLeft();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
*/
package org.apache.maven.buildcache;

import javax.annotation.Nonnull;

import org.apache.maven.buildcache.xml.config.DirScanConfig;
import org.jspecify.annotations.NonNull;
import org.jspecify.annotations.Nullable;

/**
* PluginScanConfig
Expand All @@ -33,8 +33,9 @@ public interface PluginScanConfig {

PluginScanConfig mergeWith(PluginScanConfig overrideSource);

@Nonnull
@NonNull
ScanConfigProperties getTagScanProperties(String tagName);

@Nullable
DirScanConfig dto();
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@
*/
package org.apache.maven.buildcache;

import javax.annotation.Nonnull;

import java.util.List;

import org.apache.commons.lang3.Strings;
import org.apache.maven.buildcache.xml.config.DirScanConfig;
import org.apache.maven.buildcache.xml.config.TagExclude;
import org.apache.maven.buildcache.xml.config.TagScanConfig;
import org.jspecify.annotations.NonNull;
import org.jspecify.annotations.Nullable;

/**
* PluginScanConfigImpl
Expand All @@ -34,17 +34,20 @@ public class PluginScanConfigImpl implements PluginScanConfig {

private final DirScanConfig dto;

public PluginScanConfigImpl(DirScanConfig scanConfig) {
public PluginScanConfigImpl(@Nullable DirScanConfig scanConfig) {
this.dto = scanConfig;
}

@Override
public boolean isSkip() {
return Strings.CS.equals(dto.getMode(), "skip");
return dto != null && Strings.CS.equals(dto.getMode(), "skip");
}

@Override
public boolean accept(String tagName) {
if (dto == null) {
return false;
}
// include or exclude is a choice element, could be only obe property set

//noinspection ConstantConditions
Expand All @@ -65,7 +68,7 @@ private boolean contains(List<TagExclude> excludes, String tagName) {
return false;
}

@Nonnull
@NonNull
@Override
public PluginScanConfig mergeWith(final PluginScanConfig overrideConfig) {
if (dto == null) {
Expand Down Expand Up @@ -97,17 +100,19 @@ public PluginScanConfig mergeWith(final PluginScanConfig overrideConfig) {
return new PluginScanConfigImpl(merged);
}

@Nonnull
@NonNull
public ScanConfigProperties getTagScanProperties(String tagName) {
ScanConfigProperties scanProperties = findTagScanProperties(tagName);
return scanProperties != null ? scanProperties : defaultScanConfig();
}

@Nullable
@Override
public DirScanConfig dto() {
return dto;
}

@Nullable
private ScanConfigProperties findTagScanProperties(String tagName) {
ScanConfigProperties scanConfigProperties = findConfigByName(tagName, dto.getIncludes());
if (scanConfigProperties == null) {
Expand All @@ -116,6 +121,7 @@ private ScanConfigProperties findTagScanProperties(String tagName) {
return scanConfigProperties;
}

@Nullable
private ScanConfigProperties findConfigByName(String tagName, List<TagScanConfig> configs) {
if (configs == null) {
return null;
Expand Down
Loading