Example usage for org.apache.maven.artifact.repository.metadata RepositoryMetadata storedInArtifactVersionDirectory

List of usage examples for org.apache.maven.artifact.repository.metadata RepositoryMetadata storedInArtifactVersionDirectory

Introduction

In this page you can find the example usage for org.apache.maven.artifact.repository.metadata RepositoryMetadata storedInArtifactVersionDirectory.

Prototype

boolean storedInArtifactVersionDirectory();

Source Link

Document

Whether this metadata should be stored alongside the artifact.

Usage

From source file:org.apache.archiva.converter.artifact.LegacyToDefaultConverter.java

License:Apache License

@SuppressWarnings("unchecked")
private boolean validateMetadata(Metadata metadata, RepositoryMetadata repositoryMetadata, Artifact artifact) {
    String groupIdKey;/*from  www.j a  v  a2  s.  c om*/
    String artifactIdKey = null;
    String snapshotKey = null;
    String versionKey = null;
    String versionsKey = null;

    if (repositoryMetadata.storedInGroupDirectory()) {
        groupIdKey = "failure.incorrect.groupMetadata.groupId"; //$NON-NLS-1$
    } else if (repositoryMetadata.storedInArtifactVersionDirectory()) {
        groupIdKey = "failure.incorrect.snapshotMetadata.groupId"; //$NON-NLS-1$
        artifactIdKey = "failure.incorrect.snapshotMetadata.artifactId"; //$NON-NLS-1$
        versionKey = "failure.incorrect.snapshotMetadata.version"; //$NON-NLS-1$
        snapshotKey = "failure.incorrect.snapshotMetadata.snapshot"; //$NON-NLS-1$
    } else {
        groupIdKey = "failure.incorrect.artifactMetadata.groupId"; //$NON-NLS-1$
        artifactIdKey = "failure.incorrect.artifactMetadata.artifactId"; //$NON-NLS-1$
        versionsKey = "failure.incorrect.artifactMetadata.versions"; //$NON-NLS-1$
    }

    boolean result = true;

    if (metadata.getGroupId() == null || !metadata.getGroupId().equals(artifact.getGroupId())) {
        addWarning(artifact, Messages.getString(groupIdKey));
        result = false;
    }
    if (!repositoryMetadata.storedInGroupDirectory()) {
        if (metadata.getGroupId() == null || !metadata.getArtifactId().equals(artifact.getArtifactId())) {
            addWarning(artifact, Messages.getString(artifactIdKey));
            result = false;
        }
        if (!repositoryMetadata.storedInArtifactVersionDirectory()) {
            // artifact metadata

            boolean foundVersion = false;
            if (metadata.getVersioning() != null) {
                for (String version : (List<String>) metadata.getVersioning().getVersions()) {
                    if (version.equals(artifact.getBaseVersion())) {
                        foundVersion = true;
                        break;
                    }
                }
            }

            if (!foundVersion) {
                addWarning(artifact, Messages.getString(versionsKey));
                result = false;
            }
        } else {
            // snapshot metadata
            if (!artifact.getBaseVersion().equals(metadata.getVersion())) {
                addWarning(artifact, Messages.getString(versionKey));
                result = false;
            }

            if (artifact.isSnapshot()) {
                Matcher matcher = Artifact.VERSION_FILE_PATTERN.matcher(artifact.getVersion());
                if (matcher.matches()) {
                    boolean correct = false;
                    if (metadata.getVersioning() != null && metadata.getVersioning().getSnapshot() != null) {
                        Snapshot snapshot = metadata.getVersioning().getSnapshot();
                        int build = Integer.parseInt(matcher.group(3));
                        String ts = matcher.group(2);
                        if (build == snapshot.getBuildNumber() && ts.equals(snapshot.getTimestamp())) {
                            correct = true;
                        }
                    }

                    if (!correct) {
                        addWarning(artifact, Messages.getString(snapshotKey));
                        result = false;
                    }
                }
            }
        }
    }
    return result;
}