All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.marvelution.maven.components.dependency.resolver.methods.JarAnalyzerResolveMethod Maven / Gradle / Ivy

/*
 * Licensed to Marvelution under one or more contributor license 
 * agreements.  See the NOTICE file distributed with this work 
 * for additional information regarding copyright ownership.
 * Marvelution 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 com.marvelution.maven.components.dependency.resolver.methods;

import java.io.File;
import java.io.IOException;

import org.apache.maven.artifact.Artifact;
import org.apache.maven.shared.jar.JarAnalyzer;
import org.apache.maven.shared.jar.identification.JarIdentification;
import org.apache.maven.shared.jar.identification.JarIdentificationAnalysis;
import org.codehaus.plexus.logging.AbstractLogEnabled;

import com.marvelution.maven.components.dependency.resolver.environment.ResolveEnvironment;
import com.marvelution.maven.components.dependency.resolver.methods.exception.ResolveMethodException;
import com.marvelution.utils.io.FileUtils;

/**
 * Jar Analyzer Resolver Method. This implementation uses the {@link JarIdentificationAnalysis} class to analyze the
 * Jar {@link File} to obtain {@link Artifact} information.
 * 

* Note: If not using Plexus, the following must be set before executing any resolve method: *

    *
  • the {@link Logger} implementation using method {@link #enableLogging(org.codehaus.plexus.logging.Logger)}
  • *
  • the {@link JarIdentificationAnalysis} using method * {@link #setJarIdentificationAnalysis(JarIdentificationAnalysis)}
  • *
* * @author Mark Rekveld */ public class JarAnalyzerResolveMethod extends AbstractLogEnabled { /** * Maven Jar Identification Analysis component */ private JarIdentificationAnalysis jarIdentificationAnalysis; /** * Sets the {@link JarIdentificationAnalysis} implementation to use * * @param jarIdentificationAnalysis the {@link JarIdentificationAnalysis} implementation */ public void setJarIdentificationAnalysis(JarIdentificationAnalysis jarIdentificationAnalysis) { this.jarIdentificationAnalysis = jarIdentificationAnalysis; } /** * {@inheritDoc} */ public Artifact resolve(final File library, final ResolveEnvironment environment) throws ResolveMethodException { JarIdentification identification = null; JarAnalyzer analyzer = null; try { analyzer = new JarAnalyzer(library); identification = jarIdentificationAnalysis.analyze(analyzer); } catch (IOException e) { throw new ResolveMethodException(e.getMessage(), e); } finally { if (analyzer != null) { analyzer.closeQuietly(); } } return environment.getArtifactFactory() .createArtifact(identification.getGroupId(), identification.getArtifactId(), identification.getVersion(), null, FileUtils.extension(library.getName())); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy