Search in sources :

Example 1 with Scm

use of org.apache.maven.model.Scm in project siddhi by wso2.

the class MkdocsGitHubPagesDeployMojo method execute.

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    // Finding the root maven project
    MavenProject rootMavenProject = mavenProject;
    while (rootMavenProject.getParent().getBasedir() != null) {
        rootMavenProject = rootMavenProject.getParent();
    }
    // Setting the relevant modules target directory if not set by user
    String moduleTargetPath;
    if (moduleTargetDirectory != null) {
        moduleTargetPath = moduleTargetDirectory.getAbsolutePath();
    } else {
        moduleTargetPath = mavenProject.getBuild().getDirectory();
    }
    // Setting the mkdocs config file path if not set by user
    if (mkdocsConfigFile == null) {
        mkdocsConfigFile = new File(rootMavenProject.getBasedir() + File.separator + Constants.MKDOCS_CONFIG_FILE_NAME + Constants.YAML_FILE_EXTENSION);
    }
    // Setting the documentation output directory if not set by user
    String docGenBasePath;
    if (docGenBaseDirectory != null) {
        docGenBasePath = docGenBaseDirectory.getAbsolutePath();
    } else {
        docGenBasePath = rootMavenProject.getBasedir() + File.separator + Constants.DOCS_DIRECTORY;
    }
    // Setting the home page file name if not set by user
    File homePageFile;
    if (homePageFileName == null) {
        homePageFile = new File(docGenBasePath + File.separator + Constants.HOMEPAGE_FILE_NAME + Constants.MARKDOWN_FILE_EXTENSION);
    } else {
        homePageFile = new File(docGenBasePath + File.separator + homePageFileName);
    }
    // Setting the readme file name if not set by user
    if (readmeFile == null) {
        readmeFile = new File(rootMavenProject.getBasedir() + File.separator + Constants.README_FILE_NAME + Constants.MARKDOWN_FILE_EXTENSION);
    }
    // Setting the home page template file path if not set by user
    if (homePageTemplateFile == null) {
        homePageTemplateFile = new File(rootMavenProject.getBasedir() + File.separator + Constants.README_FILE_NAME + Constants.MARKDOWN_FILE_EXTENSION);
    }
    // Retrieving metadata
    List<NamespaceMetaData> namespaceMetaDataList;
    try {
        namespaceMetaDataList = DocumentationUtils.getExtensionMetaData(moduleTargetPath, mavenProject.getRuntimeClasspathElements(), getLog());
    } catch (DependencyResolutionRequiredException e) {
        throw new MojoFailureException("Unable to resolve dependencies of the project", e);
    }
    // Generating the documentation
    if (namespaceMetaDataList.size() > 0) {
        DocumentationUtils.generateDocumentation(namespaceMetaDataList, docGenBasePath, mavenProject.getVersion(), getLog());
        DocumentationUtils.updateHeadingsInMarkdownFile(homePageTemplateFile, homePageFile, rootMavenProject.getArtifactId(), mavenProject.getVersion(), namespaceMetaDataList);
        DocumentationUtils.updateHeadingsInMarkdownFile(readmeFile, readmeFile, rootMavenProject.getArtifactId(), mavenProject.getVersion(), namespaceMetaDataList);
    }
    // Delete snapshot files
    DocumentationUtils.removeSnapshotAPIDocs(mkdocsConfigFile, docGenBasePath, getLog());
    // Updating the links in the home page to the mkdocs config
    try {
        updateAPIPagesInMkdocsConfig(mkdocsConfigFile, docGenBasePath);
    } catch (FileNotFoundException e) {
        getLog().warn("Unable to find mkdocs configuration file: " + mkdocsConfigFile.getAbsolutePath() + ". Mkdocs configuration file not updated.");
    }
    // Deploying the documentation
    if (DocumentationUtils.generateMkdocsSite(mkdocsConfigFile, getLog())) {
        // Creating the credential provider fot Git
        String scmUsername = System.getenv(Constants.SYSTEM_PROPERTY_SCM_USERNAME_KEY);
        String scmPassword = System.getenv(Constants.SYSTEM_PROPERTY_SCM_PASSWORD_KEY);
        if (scmUsername == null && scmPassword == null) {
            getLog().info("SCM_USERNAME and SCM_PASSWORD not defined!");
        }
        String url = null;
        Scm scm = rootMavenProject.getScm();
        if (scm != null) {
            url = scm.getUrl();
        }
        // Deploying documentation
        DocumentationUtils.updateDocumentationOnGitHub(docGenBasePath, mkdocsConfigFile, readmeFile, mavenProject.getVersion(), getLog());
        DocumentationUtils.deployMkdocsOnGitHubPages(mavenProject.getVersion(), rootMavenProject.getBasedir(), url, scmUsername, scmPassword, getLog());
    } else {
        getLog().warn("Unable to generate documentation. Skipping documentation deployment.");
    }
}
Also used : DependencyResolutionRequiredException(org.apache.maven.artifact.DependencyResolutionRequiredException) MavenProject(org.apache.maven.project.MavenProject) NamespaceMetaData(org.wso2.siddhi.doc.gen.commons.metadata.NamespaceMetaData) MojoFailureException(org.apache.maven.plugin.MojoFailureException) FileNotFoundException(java.io.FileNotFoundException) Scm(org.apache.maven.model.Scm) File(java.io.File)

Example 2 with Scm

use of org.apache.maven.model.Scm in project fabric8-maven-plugin by fabric8io.

the class IconEnricher method convertIconFileToURL.

private String convertIconFileToURL(File iconFile, String iconRef) throws IOException {
    long length = iconFile.length();
    int sizeK = Math.round(length / 1024);
    byte[] bytes = Files.readBytes(iconFile);
    byte[] encoded = Base64Encoder.encode(bytes);
    int base64SizeK = Math.round(encoded.length / 1024);
    if (base64SizeK < Configs.asInt(getConfig(Config.maximumDataUrlSizeK))) {
        String mimeType = guessMediaType(iconFile);
        return "data:" + mimeType + ";charset=UTF-8;base64," + new String(encoded);
    } else {
        File iconSourceFile = new File(appConfigDir, iconFile.getName());
        if (iconSourceFile.exists()) {
            File rootProjectFolder = getRootProjectFolder();
            if (rootProjectFolder != null) {
                String relativePath = Files.getRelativePath(rootProjectFolder, iconSourceFile);
                String relativeParentPath = Files.getRelativePath(rootProjectFolder, getProject().getBasedir());
                String urlPrefix = getConfig(Config.urlPrefix);
                if (Strings.isNullOrBlank(urlPrefix)) {
                    Scm scm = getProject().getScm();
                    if (scm != null) {
                        String url = scm.getUrl();
                        if (url != null) {
                            String[] prefixes = { "http://github.com/", "https://github.com/" };
                            for (String prefix : prefixes) {
                                if (url.startsWith(prefix)) {
                                    url = URLUtils.pathJoin("https://cdn.rawgit.com/", url.substring(prefix.length()));
                                    break;
                                }
                            }
                            if (url.endsWith(relativeParentPath)) {
                                url = url.substring(0, url.length() - relativeParentPath.length());
                            }
                            urlPrefix = url;
                        }
                    }
                }
                if (Strings.isNullOrBlank(urlPrefix)) {
                    log.warn("No iconUrlPrefix defined or could be found via SCM in the pom.xml so cannot add an icon URL!");
                } else {
                    String answer = URLUtils.pathJoin(urlPrefix, getConfig(Config.branch), relativePath);
                    return answer;
                }
            }
        } else {
            String embeddedIcon = embeddedIconsInConsole(iconRef, "img/icons/");
            if (embeddedIcon != null) {
                return embeddedIcon;
            } else {
                log.warn("Cannot find url for icon to use %s", iconRef);
            }
        }
    }
    return null;
}
Also used : Scm(org.apache.maven.model.Scm) File(java.io.File)

Example 3 with Scm

use of org.apache.maven.model.Scm in project fabric8-maven-plugin by fabric8io.

the class MavenScmEnricherTest method testMavenScmOnlyConnection.

@Test
public void testMavenScmOnlyConnection() {
    final MavenProject project = new MavenProject();
    final Scm scm = new Scm();
    scm.setConnection("scm:git:git://github.com/fabric8io/fabric8-maven-plugin.git");
    project.setScm(scm);
    // Setup mock behaviour
    new Expectations() {

        {
            {
                context.getProject();
                result = project;
            }
        }
    };
    MavenScmEnricher mavenScmEnricher = new MavenScmEnricher(context);
    Map<String, String> scmAnnotations = mavenScmEnricher.getAnnotations(Kind.DEPLOYMENT_CONFIG);
    assertNotNull(scmAnnotations);
    Assert.assertEquals(2, scmAnnotations.size());
    assertEquals("scm:git:git://github.com/fabric8io/fabric8-maven-plugin.git", scmAnnotations.get(MavenScmEnricher.SCM_CONNECTION));
    assertEquals("HEAD", scmAnnotations.get(MavenScmEnricher.SCM_TAG));
}
Also used : Expectations(mockit.Expectations) MavenProject(org.apache.maven.project.MavenProject) Scm(org.apache.maven.model.Scm) Test(org.junit.Test)

Example 4 with Scm

use of org.apache.maven.model.Scm in project fabric8-maven-plugin by fabric8io.

the class MavenScmEnricherTest method testMavenScmOnlyDevConnection.

@Test
public void testMavenScmOnlyDevConnection() {
    final MavenProject project = new MavenProject();
    final Scm scm = new Scm();
    scm.setUrl("git://github.com/fabric8io/fabric8-maven-plugin.git");
    project.setScm(scm);
    // Setup mock behaviour
    new Expectations() {

        {
            {
                context.getProject();
                result = project;
            }
        }
    };
    MavenScmEnricher mavenScmEnricher = new MavenScmEnricher(context);
    Map<String, String> scmAnnotations = mavenScmEnricher.getAnnotations(Kind.DEPLOYMENT_CONFIG);
    assertNotNull(scmAnnotations);
    Assert.assertEquals(2, scmAnnotations.size());
    assertEquals("git://github.com/fabric8io/fabric8-maven-plugin.git", scmAnnotations.get(MavenScmEnricher.SCM_URL));
    assertEquals("HEAD", scmAnnotations.get(MavenScmEnricher.SCM_TAG));
}
Also used : Expectations(mockit.Expectations) MavenProject(org.apache.maven.project.MavenProject) Scm(org.apache.maven.model.Scm) Test(org.junit.Test)

Example 5 with Scm

use of org.apache.maven.model.Scm in project unleash-maven-plugin by shillner.

the class DevVersionUtil method revertScmSettings.

public void revertScmSettings(MavenProject projectToRevert, Document document) {
    Scm scm = this.metadata.getCachedScmSettings(projectToRevert);
    if (scm != null) {
        this.log.debug("\t\tReversion of SCM connection tags");
        Document originalPOM = this.metadata.getCachedOriginalPOM(projectToRevert);
        Node scmNode = PomUtil.getOrCreateScmNode(document, false);
        Node originalScmNode = PomUtil.getOrCreateScmNode(originalPOM, false);
        if (scmNode != null) {
            Optional<String> connection = PomUtil.getChildNodeTextContent(originalScmNode, PomUtil.NODE_NAME_SCM_CONNECTION);
            if (connection.isPresent()) {
                PomUtil.setNodeTextContent(scmNode, PomUtil.NODE_NAME_SCM_CONNECTION, connection.get(), false);
            }
            Optional<String> devConnection = PomUtil.getChildNodeTextContent(originalScmNode, PomUtil.NODE_NAME_SCM_DEV_CONNECTION);
            if (devConnection.isPresent()) {
                PomUtil.setNodeTextContent(scmNode, PomUtil.NODE_NAME_SCM_DEV_CONNECTION, devConnection.get(), false);
            }
            Optional<String> url = PomUtil.getChildNodeTextContent(originalScmNode, PomUtil.NODE_NAME_SCM_URL);
            if (url.isPresent()) {
                PomUtil.setNodeTextContent(scmNode, PomUtil.NODE_NAME_SCM_URL, url.get(), false);
            }
            if (scm.getTag() != null) {
                PomUtil.setNodeTextContent(scmNode, PomUtil.NODE_NAME_SCM_TAG, scm.getTag(), false);
            } else {
                PomUtil.deleteNode(scmNode, PomUtil.NODE_NAME_SCM_TAG);
            }
        }
    }
}
Also used : Node(org.w3c.dom.Node) Scm(org.apache.maven.model.Scm) Document(org.w3c.dom.Document)

Aggregations

Scm (org.apache.maven.model.Scm)17 MavenProject (org.apache.maven.project.MavenProject)8 Test (org.junit.Test)5 Expectations (mockit.Expectations)4 File (java.io.File)3 Properties (java.util.Properties)2 License (org.apache.maven.model.License)2 Model (org.apache.maven.model.Model)2 MojoFailureException (org.apache.maven.plugin.MojoFailureException)2 Document (org.w3c.dom.Document)2 Node (org.w3c.dom.Node)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 ProjectToString (com.itemis.maven.plugins.unleash.util.functions.ProjectToString)1 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Artifact (org.apache.maven.artifact.Artifact)1