当前位置: 首页>>代码示例>>Java>>正文


Java EnforcerRuleException类代码示例

本文整理汇总了Java中org.apache.maven.enforcer.rule.api.EnforcerRuleException的典型用法代码示例。如果您正苦于以下问题:Java EnforcerRuleException类的具体用法?Java EnforcerRuleException怎么用?Java EnforcerRuleException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


EnforcerRuleException类属于org.apache.maven.enforcer.rule.api包,在下文中一共展示了EnforcerRuleException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testFiles

import org.apache.maven.enforcer.rule.api.EnforcerRuleException; //导入依赖的package包/类
private void testFiles(
        boolean expected,
        int expectedFaultyFilesAmount,
        @Nonnull String encoding,
        @Nonnull String dir,
        @Nonnull String includeRegex,
        @Nonnull String excludeRegex
) {
    boolean isValid;
    CharacterSetEncodingRule rule = new CharacterSetEncodingRule();
    rule.setRequireEncoding(encoding);
    rule.setDirectory(dir);
    rule.setIncludeRegex(includeRegex);
    rule.setExcludeRegex(excludeRegex);
    try {
        EnforcerRuleHelper helper = EnforcerTestUtils.getHelper();
        rule.execute(helper);
        isValid = true;
    } catch (EnforcerRuleException e) {
        // e.printStackTrace();
        isValid = false;
    }
    assertTrue(isValid == expected && rule.getFaultyFiles().size() == expectedFaultyFilesAmount);
}
 
开发者ID:mikkoi,项目名称:maven-enforcer-char-set-encoding,代码行数:25,代码来源:TestCharacterSetEncodingRule.java

示例2: detectUnmanagedModules

import org.apache.maven.enforcer.rule.api.EnforcerRuleException; //导入依赖的package包/类
private void detectUnmanagedModules(EnforcerRuleHelper helper, MavenProject project) throws ExpressionEvaluationException, EnforcerRuleException {
    Log log = helper.getLog();
    MavenSession session = RuleHelper.getSession(helper);
    List<MavenProject> projects = session.getProjects();
    ImmutableListMultimap managedDependencies = RuleHelper.getManagedDependenciesAsMap(project);

    for (MavenProject mavenProject : projects) {
        if (ruleIsDefinedInProjectOrNotModuleParent(mavenProject, log)) {
            continue;
        }
        String projectIdentifier = RuleHelper.getProjectIdentifier(mavenProject);
        if (!managedDependencies.containsKey(projectIdentifier)) {
            logHeader(log, "manage all modules");
            log.warn("unmanaged project found: " + projectIdentifier);
            failureDetected = true;
        }
    }

    if (failureDetected) {
        throw new EnforcerRuleException("Failing because of unmanaged projects");
    }
}
 
开发者ID:1and1,项目名称:ono-extra-enforcer-rules,代码行数:23,代码来源:ManageAllModulesRule.java

示例3: handleArtifacts

import org.apache.maven.enforcer.rule.api.EnforcerRuleException; //导入依赖的package包/类
@Override
protected void handleArtifacts( Set<Artifact> artifacts )
    throws EnforcerRuleException
{
    computeParameters();

    // look for banned dependencies
    Set<Artifact> foundExcludes = checkDependencies( filterArtifacts( artifacts ), getLog() );

    // if any are found, fail the check but list all of them
    if ( foundExcludes != null && !foundExcludes.isEmpty() )
    {
        StringBuilder buf = new StringBuilder();
        if ( message != null )
        {
            buf.append( message + "\n" );
        }
        for ( Artifact artifact : foundExcludes )
        {
            buf.append( getErrorMessage( artifact ) );
        }
        message = buf.toString() + "Use 'mvn dependency:tree' to locate the source of the banned dependencies.";

        throw new EnforcerRuleException( message );
    }
}
 
开发者ID:mojohaus,项目名称:extra-enforcer-rules,代码行数:27,代码来源:EnforceBytecodeVersion.java

示例4: checkDependencies

import org.apache.maven.enforcer.rule.api.EnforcerRuleException; //导入依赖的package包/类
protected Set<Artifact> checkDependencies( Set<Artifact> dependencies, Log log )
    throws EnforcerRuleException
{
    long beforeCheck = System.currentTimeMillis();
    Set<Artifact> problematic = new LinkedHashSet<Artifact>();
    for ( Iterator<Artifact> it = dependencies.iterator(); it.hasNext(); )
    {
        Artifact artifact = it.next();
        getLog().debug( "Analyzing artifact " + artifact );
        String problem = isBadArtifact( artifact );
        if ( problem != null )
        {
            getLog().info( problem );
            problematic.add( artifact );
        }
    }
    getLog().debug( "Bytecode version analysis took " + ( System.currentTimeMillis() - beforeCheck ) + " ms" );
    return problematic;
}
 
开发者ID:mojohaus,项目名称:extra-enforcer-rules,代码行数:20,代码来源:EnforceBytecodeVersion.java

示例5: checkAgainstParentValue

import org.apache.maven.enforcer.rule.api.EnforcerRuleException; //导入依赖的package包/类
/**
 * Checks the value of the project against the one given in the defining ancestor project.
 *
 * @param project
 * @param parent
 * @param helper
 * @param propValue
 * @throws EnforcerRuleException
 */
void checkAgainstParentValue( final MavenProject project, final MavenProject parent, EnforcerRuleHelper helper,
        Object propValue ) throws EnforcerRuleException
{
    final StringBuilder parentHierarchy = new StringBuilder( "project." );
    MavenProject needle = project;
    while ( !needle.equals( parent ) )
    {
        parentHierarchy.append( "parent." );
        needle = needle.getParent();
    }
    final String propertyNameInParent = property.replace( "project.", parentHierarchy.toString() );
    Object parentValue = getPropertyValue( helper, propertyNameInParent );
    if ( propValue.equals( parentValue ) )
    {
        final String errorMessage = createResultingErrorMessage( String.format(
                "Property '%s' evaluates to '%s'. This does match '%s' from parent %s",
                property, propValue, parentValue, parent ) );
        throw new EnforcerRuleException( errorMessage );
    }
}
 
开发者ID:mojohaus,项目名称:extra-enforcer-rules,代码行数:30,代码来源:RequirePropertyDiverges.java

示例6: checkValidRoles

import org.apache.maven.enforcer.rule.api.EnforcerRuleException; //导入依赖的package包/类
private void checkValidRoles( final Set<String> requiredRolesSet, final Set<String> rolesFromProject )
    throws EnforcerRuleException
{
    final Set<String> copyOfRolesFromProject = new LinkedHashSet<String>(rolesFromProject); 
    final Set<String> allowedRoles = getRolesFromString( validRoles );
    if ( !allowedRoles.contains( "*" ) )
    {
        allowedRoles.addAll( requiredRolesSet );

        // results in invalid roles
        copyOfRolesFromProject.removeAll( allowedRoles );
        if ( copyOfRolesFromProject.size() > 0 )
        {
            final String message = String.format( "Found invalid %s role(s) '%s'", getRoleName(), copyOfRolesFromProject );
            throw new EnforcerRuleException( message );
        }
    }
}
 
开发者ID:mojohaus,项目名称:extra-enforcer-rules,代码行数:19,代码来源:AbstractRequireRoles.java

示例7: testExecuteInParentWithConfigurationInPluginManagement

import org.apache.maven.enforcer.rule.api.EnforcerRuleException; //导入依赖的package包/类
/**
 * Test of execute method, of class RequirePropertyDiverges.
 */
@Test
public void testExecuteInParentWithConfigurationInPluginManagement() throws EnforcerRuleException
{
    RequirePropertyDiverges mockInstance = createMockRule();
    final MavenProject project = createMavenProject( "company", "company-parent-pom" );
    final Build build = new Build();
    // create pluginManagement
    final Plugin pluginInManagement = newPlugin( "org.apache.maven.plugins", "maven-enforcer-plugin", "1.0");
    final Xpp3Dom configuration = createPluginConfiguration();
    pluginInManagement.setConfiguration( configuration );
    final PluginManagement pluginManagement = new PluginManagement();
    pluginManagement.addPlugin( pluginInManagement );
    build.setPluginManagement( pluginManagement );
    // create plugins
    final Plugin pluginInPlugins = newPlugin( "org.apache.maven.plugins", "maven-enforcer-plugin", "1.0");
    build.addPlugin( pluginInPlugins );
    // add build
    project.getOriginalModel().setBuild( build );
    //project.getOriginalModel().setBuild( build );
    setUpHelper( project, "parentValue" );
    mockInstance.execute( helper );
}
 
开发者ID:mojohaus,项目名称:extra-enforcer-rules,代码行数:26,代码来源:RequirePropertyDivergesTest.java

示例8: testExecuteInParentWithConfigurationInExecution

import org.apache.maven.enforcer.rule.api.EnforcerRuleException; //导入依赖的package包/类
/**
 * Test of execute method, of class RequirePropertyDiverges.
 */
@Test
public void testExecuteInParentWithConfigurationInExecution() throws EnforcerRuleException
{
    RequirePropertyDiverges mockInstance = createMockRule();
    final MavenProject project = createMavenProject( "company", "company-parent-pom" );
    final Build build = new Build();
    build.setPluginManagement( new PluginManagement() );
    final Plugin plugin = newPlugin( "org.apache.maven.plugins", "maven-enforcer-plugin", "1.0" );
    final Xpp3Dom configuration = createPluginConfiguration();
    PluginExecution pluginExecution = new PluginExecution();
    pluginExecution.setConfiguration( configuration );
    plugin.addExecution( pluginExecution );
    build.addPlugin( plugin );
    project.getOriginalModel().setBuild( build );
    setUpHelper(project, "parentValue");
    mockInstance.execute( helper );
}
 
开发者ID:mojohaus,项目名称:extra-enforcer-rules,代码行数:21,代码来源:RequirePropertyDivergesTest.java

示例9: execute

import org.apache.maven.enforcer.rule.api.EnforcerRuleException; //导入依赖的package包/类
public void execute(EnforcerRuleHelper helper) throws EnforcerRuleException {
    Log log = helper.getLog();

    List<Pattern> excludedPatterns = new ArrayList<Pattern>(excludes.size());
    for (String exclude : excludes) {
        excludedPatterns.add(Pattern.compile(exclude));
    }

    try {
        MavenProject project = (MavenProject) helper.evaluate("${project}");
        List<Artifact> artifactList = project.getAttachedArtifacts();
        for (Artifact artifact : artifactList) {
            String artifactFileName = artifact.getFile().getName();
            log.debug("evaluating artifact [" + artifactFileName + "]");
            for (Pattern pattern : excludedPatterns) {
                if (pattern.matcher(artifactFileName).matches()) {
                    throw new EnforcerRuleException("found banned attached artifact: artifact [" + artifactFileName + "] matched exclude pattern [" + pattern.toString() + "]");
                }
            }
        }

    } catch (ExpressionEvaluationException e) {
        throw new EnforcerRuleException("Unable to lookup expression", e);
    }

}
 
开发者ID:elastic,项目名称:attached-artifact-enforcer,代码行数:27,代码来源:BannedAttachedArtifacts.java

示例10: resolveTransitiveDependencies

import org.apache.maven.enforcer.rule.api.EnforcerRuleException; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private Set<Artifact> resolveTransitiveDependencies(Artifact artifact) throws EnforcerRuleException {
  final DependencyNode root;
  try {
    root = dependencyGraphBuilder.buildDependencyGraph(project, null);
  } catch (DependencyGraphBuilderException e) {
    throw new EnforcerRuleException("Unable to build the dependency graph!", e);
  }
  if (logger.isDebugEnabled()) {
    logger.debug("Root node is '" + root + "'.");
  }

  final Set<Artifact> transitiveDependencies = new HashSet<Artifact>();
  traverseDependencyNodes(root, transitiveDependencies);

  final Set<Artifact> directDependencies = resolveDirectDependencies(artifact);
  transitiveDependencies.removeAll(directDependencies);
  if (logger.isDebugEnabled()) {
    logger.debug("Transitive dependencies are '" + transitiveDependencies + "'.");
  }
  return transitiveDependencies;
}
 
开发者ID:ImmobilienScout24,项目名称:illegal-transitive-dependency-check,代码行数:23,代码来源:IllegalTransitiveDependencyCheck.java

示例11: traverseDependencyNodes

import org.apache.maven.enforcer.rule.api.EnforcerRuleException; //导入依赖的package包/类
private void traverseDependencyNodes(DependencyNode node, Set<Artifact> transitiveDependencies)
  throws EnforcerRuleException {
  final List<DependencyNode> children = node.getChildren();
  if ((children == null) || children.isEmpty()) {
    return;
  }
  for (DependencyNode child : children) {
    final Artifact artifact = child.getArtifact();
    enforceArtifactResolution(artifact);
    if (logger.isDebugEnabled()) {
      logger.debug("Add dependency '" + artifact.getId() + "'");
    }
    transitiveDependencies.add(artifact);
    traverseDependencyNodes(child, transitiveDependencies);
  }
}
 
开发者ID:ImmobilienScout24,项目名称:illegal-transitive-dependency-check,代码行数:17,代码来源:IllegalTransitiveDependencyCheck.java

示例12: buildOutput

import org.apache.maven.enforcer.rule.api.EnforcerRuleException; //导入依赖的package包/类
private String buildOutput(Artifact artifact, Set<String> unresolvedTypes) throws EnforcerRuleException {
  final StringBuilder output = new StringBuilder();
  output.append("Found ")
    .append(unresolvedTypes.size())
    .append(" illegal transitive type dependencies in artifact '")
    .append(artifact.getId())
    .append("':\n");

  final List<String> illegalTransitiveDependencies;
  if (listMissingArtifacts) {
    illegalTransitiveDependencies = new ArrayList<String>(
      findArtifactsForUnresolvedTypes(artifact, unresolvedTypes));
  } else {
    illegalTransitiveDependencies = new ArrayList<String>(unresolvedTypes);
  }

  Collections.sort(illegalTransitiveDependencies);

  int k = 1;
  for (String illegalTransitiveDependency : illegalTransitiveDependencies) {
    output.append(k).append(".) ").append(illegalTransitiveDependency).append("\n");
    k++;
  }
  return output.toString();
}
 
开发者ID:ImmobilienScout24,项目名称:illegal-transitive-dependency-check,代码行数:26,代码来源:IllegalTransitiveDependencyCheck.java

示例13: findArtifactsForUnresolvedTypes

import org.apache.maven.enforcer.rule.api.EnforcerRuleException; //导入依赖的package包/类
private Set<String> findArtifactsForUnresolvedTypes(Artifact artifact, Set<String> unresolvedTypes)
  throws EnforcerRuleException {
  final Set<Artifact> transitiveDependencies = resolveTransitiveDependencies(artifact);
  final Set<String> unresolvedTypesWithArtifact = new HashSet<String>();

  for (Artifact transitiveDependency : transitiveDependencies) {
    // skip further artifacts if all types have been found
    if (unresolvedTypesWithArtifact.size() == unresolvedTypes.size()) {
      break;
    }

    final Repository repository = ArtifactRepositoryAnalyzer.analyzeArtifacts(logger,
      false,
      filter)
      .analyzeArtifacts(Collections.singleton(transitiveDependency));

    final Set<String> repositoryTypes = repository.getTypes();
    for (String unresolvedType : unresolvedTypes) {
      if (repositoryTypes.contains(unresolvedType)) {
        unresolvedTypesWithArtifact.add(unresolvedType + ", [" + transitiveDependency.getId() + "]");
      }
    }
  }
  return unresolvedTypesWithArtifact;
}
 
开发者ID:ImmobilienScout24,项目名称:illegal-transitive-dependency-check,代码行数:26,代码来源:IllegalTransitiveDependencyCheck.java

示例14: checkDependencies

import org.apache.maven.enforcer.rule.api.EnforcerRuleException; //导入依赖的package包/类
protected Set<Artifact> checkDependencies(Set<Artifact> theDependencies, Log log) throws EnforcerRuleException {
    initConfig(log);
    Set<Artifact> excluded = checkDependencies(theDependencies, excludes);
    if (excluded != null) {
        Set<Artifact> included = checkDependencies(theDependencies, includes);
        if (included != null) {
            excluded.removeAll(included);
        }
    }
    if (!warnings.isEmpty()) {
        Set<Artifact> warningList = checkDependencies(theDependencies, warnings);
        if (warningList != null) {
            log.warn("========== BannedDependenciesEX Deprecated Warning Start ==========");
            log.warn("group of this project:\t" + root.getGroupId());
            log.warn("artifact of this project:\t" + root.getArtifactId());
            log.warn("version of this project:\t" + root.getVersion());
            log.warn("---------------------------------------------------------------------");
            for (Artifact aft : warningList)
                log.warn(aft.toString());
            log.warn("========== BannedDependenciesEX Deprecated Warning END ==========");
            // Post Data to Server
        }
    }
    return excluded;
}
 
开发者ID:peiliping,项目名称:excalibur,代码行数:26,代码来源:BannedDependenciesEX.java

示例15: execute

import org.apache.maven.enforcer.rule.api.EnforcerRuleException; //导入依赖的package包/类
public void execute(EnforcerRuleHelper helper) throws EnforcerRuleException {
    Log log = helper.getLog();

    try {
        // get the various expressions out of the helper.
        MavenProject project = (MavenProject) helper.evaluate("${project}");
        // MavenSession session = (MavenSession) helper.evaluate("${session}");
        // String target = (String) helper.evaluate("${project.build.directory}");
        // String artifactId = (String) helper.evaluate("${project.artifactId}");

        // ArtifactResolver resolver = (ArtifactResolver) helper.getComponent(ArtifactResolver.class);
        // RuntimeInfo rti = (RuntimeInfo) helper.getComponent(RuntimeInfo.class);
        List compileSourceRoots = project.getCompileSourceRoots();

        for (Object compileSourceRoot : compileSourceRoots) {
            String path = (String) compileSourceRoot;
            applyForJavaSourcesInRoot(path, log);
        }
    } catch (ExpressionEvaluationException e) {
        throw new EnforcerRuleException("Unable to lookup an expression " + e.getLocalizedMessage(), e);
    }
}
 
开发者ID:CloudSlang,项目名称:cloud-slang,代码行数:23,代码来源:SpringCleansingRule.java


注:本文中的org.apache.maven.enforcer.rule.api.EnforcerRuleException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。