org.jenkinsci.Symbol Java Examples

The following examples show how to use org.jenkinsci.Symbol. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Tool.java    From warnings-ng-plugin with MIT License 5 votes vote down vote up
/**
 * Returns the {@link Symbol} name of this tool.
 *
 * @return the name of this tool, or "undefined" if no symbol has been defined
 */
public String getSymbolName() {
    Symbol annotation = getClass().getAnnotation(Symbol.class);

    if (annotation != null) {
        String[] symbols = annotation.value();
        if (symbols.length > 0) {
            return symbols[0];
        }
    }
    return "unknownSymbol";
}
 
Example #2
Source File: DescriptorConfigurator.java    From configuration-as-code-plugin with MIT License 5 votes vote down vote up
private List<String> resolvePossibleNames(Descriptor descriptor) {
    return Optional.ofNullable(descriptor.getClass().getAnnotation(Symbol.class))
            .map(s -> Arrays.asList(s.value()))
            .orElseGet(() -> {
                /* TODO: extract Descriptor parameter type such that DescriptorImpl extends Descriptor<XX> returns XX.
                 * Then, if `baseClass == fooXX` we get natural name `foo`.
                 */
                return singletonList(CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_CAMEL, descriptor.getKlass().toJavaClass().getSimpleName()));
            });
}
 
Example #3
Source File: GlobalConfigurationCategoryConfigurator.java    From configuration-as-code-plugin with MIT License 5 votes vote down vote up
@NonNull
@Override
public List<String> getNames() {
    final Class c = category.getClass();
    final Symbol symbol = (Symbol) c.getAnnotation(Symbol.class);
    if (symbol != null) return asList(symbol.value());

    String name = c.getSimpleName();
    name = StringUtils.remove(name, "Global");
    name = StringUtils.remove(name, "Configuration");
    name = StringUtils.remove(name, "Category");
    return singletonList(name.toLowerCase());
}
 
Example #4
Source File: DescribableAttribute.java    From configuration-as-code-plugin with MIT License 5 votes vote down vote up
/**
 * Retrieve all possible symbols for this descriptor, first one being preferred one.
 * If a {@link Symbol} annotation is set, all values are accepted the last one being preferred
 */
public static List<String> getSymbols(Descriptor d, Class extensionPoint, Class target) {

    if (d != null) {
        List<String> symbols = new ArrayList<>();
        // explicit @Symbol annotation on descriptor
        // first is the preferred one as by Symbol contract
        // "The first one is used as the primary identifier for reverse-mapping."
        Symbol s = d.getClass().getAnnotation(Symbol.class);
        if (s != null) {
            symbols.addAll(Arrays.asList(s.value()));
        }

        // extension type Foo is implemented as SomeFoo. => "some"
        final String ext = extensionPoint.getSimpleName();
        final String cn = d.getKlass().toJavaClass().getSimpleName();
        if (cn.endsWith(ext)) {
            symbols.add( normalize(cn.substring(0, cn.length() - ext.length())) );
        }

        // extension type Foo is implemented as SomeFooImpl. => "some"
        final String in = extensionPoint.getSimpleName() + "Impl";
        if (cn.endsWith(in)) {
            symbols.add( normalize(cn.substring(0, cn.length() - in.length())) );
        }

        // Fall back to simple class name
        symbols.add( normalize(cn) );
        return symbols;
    }

    // Fall back to simple class name
    return Collections.singletonList(normalize(target.getSimpleName()));

}
 
Example #5
Source File: Configurator.java    From configuration-as-code-plugin with MIT License 5 votes vote down vote up
/**
 * Get all possible configurator names
 *
 * @return a list of all possible short names for this component when used in a configuration.yaml file
 */
@NonNull
default List<String> getNames() {
    final Symbol annotation = getTarget().getAnnotation(Symbol.class);
    if (annotation != null) {
        return Arrays.asList(annotation.value());
    }
    return Collections.singletonList(normalize(getTarget().getSimpleName()));
}
 
Example #6
Source File: WithMavenStepGlobalConfigurationTest.java    From pipeline-maven-plugin with MIT License 5 votes vote down vote up
private void maven_build_jar_project_on_master_with_globally_disabled_publisher_succeeds(MavenPublisher.DescriptorImpl descriptor) throws Exception {

        MavenPublisher publisher = descriptor.clazz.newInstance();
        publisher.setDisabled(true);

        GlobalPipelineMavenConfig globalPipelineMavenConfig = GlobalPipelineMavenConfig.get();

        globalPipelineMavenConfig.setPublisherOptions(Collections.singletonList(publisher));
        Logger logger = Logger.getLogger(MavenSpyLogProcessor.class.getName());
        Level level = logger.getLevel();
        logger.setLevel(Level.FINE);
        try {


            Symbol symbolAnnotation = descriptor.getClass().getAnnotation(Symbol.class);
            String symbol = symbolAnnotation.value()[0];
            String displayName = descriptor.getDisplayName();

            loadMavenJarProjectInGitRepo(this.gitRepoRule);

            String pipelineScript = "node('master') {\n" +
                    "    git($/" + gitRepoRule.toString() + "/$)\n" +
                    "    withMaven() {\n" +
                    "        sh 'mvn package verify'\n" +
                    "    }\n" +
                    "}";

            WorkflowJob pipeline = jenkinsRule.createProject(WorkflowJob.class, "build-on-master-" + symbol + "-publisher-globally-disabled");
            pipeline.setDefinition(new CpsFlowDefinition(pipelineScript, true));
            WorkflowRun build = jenkinsRule.assertBuildStatus(Result.SUCCESS, pipeline.scheduleBuild2(0));

            String message = "[withMaven] Skip '" + displayName + "' disabled by configuration";
            jenkinsRule.assertLogContains(message, build);
        } finally {
            logger.setLevel(level);
            globalPipelineMavenConfig.setPublisherOptions((List<MavenPublisher>) null);
        }
    }
 
Example #7
Source File: WithMavenStepGlobalConfigurationTest.java    From pipeline-maven-plugin with MIT License 5 votes vote down vote up
private void maven_build_jar_project_on_master_with_publisher_configured_both_globally_and_on_the_pipeline_succeeds(MavenPublisher.DescriptorImpl descriptor) throws Exception {

        MavenPublisher publisher = descriptor.clazz.newInstance();
        publisher.setDisabled(true);

        GlobalPipelineMavenConfig globalPipelineMavenConfig = GlobalPipelineMavenConfig.get();

        globalPipelineMavenConfig.setPublisherOptions(Collections.singletonList(publisher));
        Logger logger = Logger.getLogger(MavenSpyLogProcessor.class.getName());
        Level level = logger.getLevel();
        logger.setLevel(Level.FINE);
        try {


            Symbol symbolAnnotation = descriptor.getClass().getAnnotation(Symbol.class);
            String symbol = symbolAnnotation.value()[0];
            String displayName = descriptor.getDisplayName();

            loadMavenJarProjectInGitRepo(this.gitRepoRule);

            String pipelineScript = "node('master') {\n" +
                    "    git($/" + gitRepoRule.toString() + "/$)\n" +
                    "    withMaven(options:[" + symbol + "(disabled: true)]) {\n" +
                    "        sh 'mvn package verify'\n" +
                    "    }\n" +
                    "}";

            WorkflowJob pipeline = jenkinsRule.createProject(WorkflowJob.class, "build-on-master-" + symbol + "-publisher-defined-globally-and-in-the-pipeline");
            pipeline.setDefinition(new CpsFlowDefinition(pipelineScript, true));
            WorkflowRun build = jenkinsRule.assertBuildStatus(Result.SUCCESS, pipeline.scheduleBuild2(0));

            jenkinsRule.assertLogContains("[withMaven] WARNING merging publisher configuration defined in the 'Global Tool Configuration' and at the pipeline level is not yet supported. " +
                    "Use pipeline level configuration for '" + displayName +                     "'", build);
            jenkinsRule.assertLogContains("[withMaven] Skip '" + displayName + "' disabled by configuration", build);
        } finally {
            logger.setLevel(level);
            globalPipelineMavenConfig.setPublisherOptions((List<MavenPublisher>) null);
        }
    }
 
Example #8
Source File: WithMavenStepOnMasterTest.java    From pipeline-maven-plugin with MIT License 5 votes vote down vote up
private void maven_build_jar_project_on_master_with_disabled_publisher_param_succeeds(MavenPublisher.DescriptorImpl descriptor, String symbol, boolean disabled) throws Exception {

        Logger logger = Logger.getLogger(MavenSpyLogProcessor.class.getName());
        Level level = logger.getLevel();
        logger.setLevel(Level.FINE);
        try {
            String displayName = descriptor.getDisplayName();

            Symbol symbolAnnotation = descriptor.getClass().getAnnotation(Symbol.class);
            String[] symbols = symbolAnnotation.value();
            assertThat(new String[]{symbol}, is(symbols));

            loadMavenJarProjectInGitRepo(this.gitRepoRule);

            String pipelineScript = "node('master') {\n" +
                    "    git($/" + gitRepoRule.toString() + "/$)\n" +
                    "    withMaven(options:[" + symbol + "(disabled:" + disabled + ")]) {\n" +
                    "        sh 'mvn package verify'\n" +
                    "    }\n" +
                    "}";

            WorkflowJob pipeline = jenkinsRule.createProject(WorkflowJob.class, "build-on-master-" + symbol + "-publisher-disabled-" + disabled);
            pipeline.setDefinition(new CpsFlowDefinition(pipelineScript, true));
            WorkflowRun build = jenkinsRule.assertBuildStatus(Result.SUCCESS, pipeline.scheduleBuild2(0));

            String message = "[withMaven] Skip '" + displayName + "' disabled by configuration";
            if (disabled) {
                jenkinsRule.assertLogContains(message, build);
            } else {
                jenkinsRule.assertLogNotContains(message, build);
            }
        } finally {
            logger.setLevel(level);
        }
    }
 
Example #9
Source File: WithMavenStepOnMasterTest.java    From pipeline-maven-plugin with MIT License 5 votes vote down vote up
@Test
public void maven_build_jar_project_on_master_with_open_task_scanner_config_succeeds() throws Exception {

    MavenPublisher.DescriptorImpl descriptor = new TasksScannerPublisher.DescriptorImpl();
    String displayName = descriptor.getDisplayName();

    Symbol symbolAnnotation = descriptor.getClass().getAnnotation(Symbol.class);
    String[] symbols = symbolAnnotation.value();
    assertThat(new String[]{"openTasksPublisher"},  is(symbols));

    loadMavenJarProjectInGitRepo(this.gitRepoRule);

    String pipelineScript = "node('master') {\n" +
            "    git($/" + gitRepoRule.toString() + "/$)\n" +
            "    withMaven(options:[openTasksPublisher(" +
            "       disabled:false, " +
            "       pattern:'src/main/java', excludePattern:'a/path'," +
            "       ignoreCase:true, asRegexp:false, " +
            "       lowPriorityTaskIdentifiers:'minor', normalPriorityTaskIdentifiers:'todo', highPriorityTaskIdentifiers:'fixme')]) {\n" +
            "           sh 'mvn package verify'\n" +
            "    }\n" +
            "}";

    WorkflowJob pipeline = jenkinsRule.createProject(WorkflowJob.class, "build-on-master-openTasksPublisher-publisher-config");
    pipeline.setDefinition(new CpsFlowDefinition(pipelineScript, true));
    WorkflowRun build = jenkinsRule.assertBuildStatus(Result.SUCCESS, pipeline.scheduleBuild2(0));

    String message = "[withMaven] Skip '" + displayName + "' disabled by configuration";
    jenkinsRule.assertLogNotContains(message, build);
}