Java tutorial
/* * Copyright 2005-2006 The Apache Software Foundation. * * Licensed 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. * * User: freds * Date: Mar 27, 2007 * Time: 12:08:45 PM */ package org.jfrog.jade.plugins.natives.plugin; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.handler.ArtifactHandler; import org.apache.maven.model.Dependency; import org.apache.maven.project.MavenProject; import org.codehaus.plexus.util.StringUtils; import org.jfrog.jade.plugins.common.naming.ProjectNameProviderImpl; public class NativeNameProvider extends ProjectNameProviderImpl { public String getProjectName(MavenProject project) { Artifact artifact = project.getArtifact(); boolean isLib = isLibrary(artifact); return getProjectName(project.getGroupId(), project.getArtifactId(), isLib); } private String getProjectName(String groupId, String artifactId, boolean library) { String result; String groupName = getGroupName(groupId); if (library) { if (!StringUtils.isEmpty(groupName)) { result = "lib" + groupName + getLibArtifactId(artifactId); } else { result = getLibFileName(artifactId); } } else { if (!StringUtils.isEmpty(groupName)) { result = groupName + artifactId; } else { result = artifactId; } } return result; } public String getProjectName(Artifact artifact) { return getProjectName(artifact.getGroupId(), artifact.getArtifactId(), isLibrary(artifact)); } public String getProjectName(Dependency dependency) { return getProjectName(dependency.getGroupId(), dependency.getArtifactId(), isLibrary(dependency.getType())); } public static boolean isLibrary(Artifact artifact) { if (artifact == null) return false; ArtifactHandler artifactHandler = artifact.getArtifactHandler(); if (artifactHandler == null) return false; String extension = artifactHandler.getExtension(); return isLibrary(extension); } private static boolean isLibrary(String extension) { return extension != null && (extension.equals("so") || extension.equals("a") || extension.equals("dll") || extension.equals("lib") || extension.equals("dylib")); } private static boolean isDynamicLibrary(String extension) { return extension != null && (extension.equals("so") || extension.equals("dll") || extension.equals("dylib")); } private String getLibFileName(String artifactId) { String libFileName = artifactId; if (!libFileName.startsWith("lib")) { libFileName = "lib" + libFileName; } return libFileName; } private String getLibArtifactId(String libFileName) { String artifactId = libFileName; if (artifactId.startsWith("lib")) { artifactId = artifactId.substring(3); } return artifactId; } }