Get repository and throw a {@link MojoExecutionException} on failures

@param project
@param owner
@param name
@return non-null repository id
@throws MojoExecutionException
195843
protected RepositoryId getRepository(final MavenProject project,
			final String owner, final String name)
			throws MojoExecutionException {
		RepositoryId repository = RepositoryUtils.getRepository(project, owner,
				name);
		if (repository == null)
			throw new MojoExecutionException(
					"No GitHub repository (owner and name) configured");
		if (isDebug())
			debug(MessageFormat.format("Using GitHub repository {0}",
					repository.generateId()));
		return repository;
	}
228873
@Get("/projects/{projectName}/repos")
    public CompletableFuture<List<RepositoryDto>> listRepositories(ServiceRequestContext ctx, Project project,
                                                                   @Param("status") Optional<String> status,
                                                                   User user) {
        status.ifPresent(HttpApiUtil::checkStatusArgument);
        return mds.findRole(project.name(), user).handle((role, throwable) -> {
            final boolean hasOwnerRole = role == ProjectRole.OWNER;
            if (status.isPresent()) {
                if (hasOwnerRole) {
                    return project.repos().listRemoved().stream().map(RepositoryDto::new)
                                  .collect(toImmutableList());
                }
                return HttpApiUtil.throwResponse(
                        ctx, HttpStatus.FORBIDDEN,
                        "You must be an owner of project '%s' to remove it.", project.name());
            }

            // Do not add internal repository to the list if the user is not an administrator.
            return project.repos().list().values().stream()
                          .filter(r -> user.isAdmin() || !Project.REPO_DOGMA.equals(r.name()))
                          .map(DtoConverter::convert)
                          .collect(toImmutableList());
        });
    }
1174988
private void addProjectProperties() throws MojoExecutionException
    {
        Properties projectProps = mavenProject.getProperties();
        
        projectProps.setProperty( PROPERTY_NAME_COMPANY, versionInfo.getCompanyName() );
        projectProps.setProperty( PROPERTY_NAME_COPYRIGHT, versionInfo.getCopyright() );

        projectProps.setProperty( PROPERTY_NAME_VERSION_MAJOR, "0" );
        projectProps.setProperty( PROPERTY_NAME_VERSION_MINOR, "0" );
        projectProps.setProperty( PROPERTY_NAME_VERSION_INCREMENTAL, "0" );
        projectProps.setProperty( PROPERTY_NAME_VERSION_BUILD, "0" );
        String version = mavenProject.getVersion();
        if ( version != null && version.length() > 0 )
        {
            ArtifactVersion artifactVersion = new DefaultArtifactVersion( version );
            if ( version.equals( artifactVersion.getQualifier() ) )
            {
                String msg = "Unable to parse the version string, please use standard maven version format.";
                getLog().error( msg );
                throw new MojoExecutionException( msg );
            }
            projectProps.setProperty( PROPERTY_NAME_VERSION_MAJOR, 
                    String.valueOf( artifactVersion.getMajorVersion() ) );
            projectProps.setProperty( PROPERTY_NAME_VERSION_MINOR, 
                    String.valueOf( artifactVersion.getMinorVersion() ) );
            projectProps.setProperty( PROPERTY_NAME_VERSION_INCREMENTAL, 
                    String.valueOf( artifactVersion.getIncrementalVersion() ) );
            projectProps.setProperty( PROPERTY_NAME_VERSION_BUILD, 
                    String.valueOf( artifactVersion.getBuildNumber() ) );
        }
        else
        {
            getLog().warn( "Missing version for project. Version parts will be set to 0" );
        }
    }
860660
private String getOutputName() throws MojoExecutionException
    {
        if ( MSBuildPackaging.isSolution( mavenProject.getPackaging() ) )
        {
            throw new MojoExecutionException( "Internal error: Cannot determine single output name for a solutions" );
        }
        String projectFileName = projectFile.getName();
        if ( ! projectFileName.contains( "." ) )
        {
            throw new MojoExecutionException( "Project file name has no extension, please check your configuration" );
        }
        projectFileName = projectFileName.substring( 0, projectFileName.lastIndexOf( '.' ) );
        return projectFileName;
    }
486267
@GetMapping("/mappingproject/{id}")
  public String viewMappingProject(@PathVariable("id") String identifier, Model model) {
    MappingProject project = mappingService.getMappingProject(identifier);
    MappingTarget mappingTarget = project.getMappingTargets().get(0);
    String target = mappingTarget.getName();
    model.addAttribute("entityTypes", getNewSources(mappingTarget));
    model.addAttribute(
        "compatibleTargetEntities",
        mappingService.getCompatibleEntityTypes(mappingTarget.getTarget()).collect(toList()));
    model.addAttribute("selectedTarget", target);
    model.addAttribute("mappingProject", project);
    model.addAttribute("attributeTagMap", getTagsForAttribute(target, project));
    model.addAttribute(
        "packages",
        dataService
            .getMeta()
            .getPackages()
            .stream()
            .filter(p -> !isSystemPackage(p))
            .collect(toList()));
    return VIEW_SINGLE_MAPPING_PROJECT;
  }
374214
public void execute()
        throws MojoExecutionException, MojoFailureException
    {
        File jarFile = new File( outputDirectory, finalName + ".jar" );
        File origJarFile = new File( outputDirectory, finalName + "-b4gwt.jar" );
        if ( origJarFile.exists() )
        {
            if ( !origJarFile.delete() )
            {
                throw new MojoExecutionException( "Error removing " + origJarFile );
            }
        }
        if ( !jarFile.renameTo( origJarFile ) )
        {
            throw new MojoExecutionException( "Error renaming " + jarFile + " to " + origJarFile );
        }

        MavenArchiver archiver = new MavenArchiver();

        archiver.setArchiver( jarArchiver );
        archiver.setOutputFile( jarFile );
        archive.setForced( false );
        // It is already created by maven-jar-plugin
        archive.setAddMavenDescriptor( false );

        Collection<ResourceFile> files = getAllResourceFiles();
        try
        {

            // Avoid annoying messages in log "com/package/Ccc.java already added, skipping"
            List<String> jarExcludes = new Vector<String>();

            // Add Sources first since they may already be present in jar from previous run and changed.
            for ( ResourceFile file : files )
            {
                jarArchiver.addFile( new File( file.basedir, file.fileRelativeName ), file.fileRelativeName );
                jarExcludes.add( file.fileRelativeName );
            }

            // Add the context of original jar excluding resources that we just added base on GWT descriptors
            jarArchiver.addArchivedFileSet( origJarFile, null, jarExcludes.toArray( new String[jarExcludes.size()] ) );

            archiver.createArchive( session , getProject(), archive );
        }
        catch ( Exception e )
        {
            throw new MojoExecutionException( "Error assembling JAR", e );
        }

    }
735745
public String getRevision()
        throws MojoExecutionException
    {

        if ( format != null && !useScm )
        {
            return revision;
        }
        useScm = false;

        try
        {
            return this.getScmRevision();
        }
        catch ( ScmException e )
        {
            if ( !StringUtils.isEmpty( revisionOnScmFailure ) )
            {
                getLog().warn( "Cannot get the revision information from the scm repository, proceeding with "
                    + "revision of " + revisionOnScmFailure + " : \n" + e.getLocalizedMessage() );

                setDoCheck( false );
                setDoUpdate( false );

                return revisionOnScmFailure;
            }

            throw new MojoExecutionException( "Cannot get the revision information from the scm repository : \n"
                + e.getLocalizedMessage(), e );

        }

    }
604844
public static void initializeInternalProject(CommandExecutor executor) {
        final long creationTimeMillis = System.currentTimeMillis();
        try {
            executor.execute(createProject(creationTimeMillis, Author.SYSTEM, INTERNAL_PROJ))
                    .get();
        } catch (Throwable cause) {
            cause = Exceptions.peel(cause);
            if (!(cause instanceof ProjectExistsException)) {
                throw new Error("failed to initialize an internal project", cause);
            }
        }
        // These repositories might be created when creating an internal project, but we try to create them
        // again here in order to make sure them exist because sometimes their names are changed.
        for (final String repo : ImmutableList.of(Project.REPO_META, Project.REPO_DOGMA)) {
            try {
                executor.execute(createRepository(creationTimeMillis, Author.SYSTEM, INTERNAL_PROJ, repo))
                        .get();
            } catch (Throwable cause) {
                cause = Exceptions.peel(cause);
                if (!(cause instanceof RepositoryExistsException)) {
                    throw new Error(cause);
                }
            }
        }
    }
1156221
@CheckForNull
    public static GitHubRepositoryName create(GithubProjectProperty projectProperty) {
        if (projectProperty == null) {
            return null;
        }

        return GitHubRepositoryName.create(projectProperty.getProjectUrlStr());
    }
546526
public void execute() throws MojoExecutionException, MojoFailureException {
		try {
			createBundles();
		} catch (Exception ex) {
			Logger logger = Logger.getLogger(JawrMojo.class.getName());
			if(ex instanceof ServletException){
				logger.log(Level.SEVERE, null, ((ServletException)ex).getRootCause());
			}else{
				logger.log(Level.SEVERE, null, ex);
			}
			throw new MojoFailureException("JAWR Maven plugin failed: " + ex.getLocalizedMessage());
		}
	}
681049
@SuppressWarnings( "unchecked" )
    private List<String> findOptionalMojosForLifecycle( MavenProject project, Lifecycle lifecycle )
        throws LifecycleExecutionException, PluginNotFoundException
    {
        String packaging = project.getPackaging();
        List<String> optionalMojos = null;

        LifecycleMapping m =
            (LifecycleMapping) findExtension( project, LifecycleMapping.ROLE, packaging, session.getSettings(),
                                              session.getLocalRepository() );

        if ( m != null )
        {
            optionalMojos = m.getOptionalMojos( lifecycle.getId() );
        }

        if ( optionalMojos == null )
        {
            try
            {
                m = (LifecycleMapping) session.lookup( LifecycleMapping.ROLE, packaging );
                optionalMojos = m.getOptionalMojos( lifecycle.getId() );
            }
            catch ( ComponentLookupException e )
            {
                log.debug( "Error looking up lifecycle mapping to retrieve optional mojos. Lifecycle ID: "
                    + lifecycle.getId() + ". Error: " + e.getMessage(), e );
            }
        }

        if ( optionalMojos == null )
        {
            optionalMojos = Collections.emptyList();
        }

        return optionalMojos;
    }
807324
public void execute()
        throws MojoFailureException
    {
        Interpreter interpreter = new Interpreter();

        set( interpreter, "project", getProject() );
        set( interpreter, "session", mavenSession );
        set( interpreter, "settings", settings );

        try
        {
            interpreter.eval( source );
        }
        catch ( EvalError ee )
        {
            MojoFailureException mfe =
                new MojoFailureException( "error during Beanshell script execution: " + ee.getMessage() );
            mfe.initCause( ee );
            throw mfe;
        }

        if ( properties != null )
        {
            for ( String property : properties )
            {
                Object value;
                try
                {
                    value = interpreter.get( property );

                    if ( value != null )
                    {
                        defineProperty( property, value.toString() );
                    }
                }
                catch ( EvalError ee )
                {
                    MojoFailureException mfe = new MojoFailureException( "cannot get Beanshell global variable '"
                        + property + "': " + ee.getMessage() );
                    mfe.initCause( ee );
                    throw mfe;
                }
            }
        }
    }
76685
def get_repository(name=None):
    
    repo_mgr = get_repository_manager()
    if name is None:
        repo = repo_mgr.get_default()
    else:
        repo = repo_mgr.get(name)
    return repo
806560
@Override
    protected ExceptionCollection scanDependencies(final Engine engine) throws MojoExecutionException {
        ExceptionCollection exCol = scanArtifacts(getProject(), engine, true);
        for (MavenProject childProject : getDescendants(this.getProject())) {
            final ExceptionCollection ex = scanArtifacts(childProject, engine, true);
            if (ex != null) {
                if (exCol == null) {
                    exCol = ex;
                }
                exCol.getExceptions().addAll(ex.getExceptions());
                if (ex.isFatal()) {
                    exCol.setFatal(true);
                    final String msg = String.format("Fatal exception(s) analyzing %s", childProject.getName());
                    if (this.isFailOnError()) {
                        throw new MojoExecutionException(msg, exCol);
                    }
                    getLog().error(msg);
                    if (getLog().isDebugEnabled()) {
                        getLog().debug(exCol);
                    }
                }
            }
        }
        return exCol;
    }
138203
@Override
    public void execute() throws MojoExecutionException {
        try {
            // Work around for Application Insights Java SDK:
            // Sometimes, NoClassDefFoundError will be thrown even after Maven build is completed successfully.
            // An issue has been filed at https://github.com/Microsoft/ApplicationInsights-Java/issues/416
            // Before this issue is fixed, set default uncaught exception handler for all threads as work around.
            Thread.setDefaultUncaughtExceptionHandler(new DefaultUncaughtExceptionHandler());

            final Properties prop = new Properties();
            if (isFirstRun(prop)) {
                infoWithMultipleLines(PRIVACY_STATEMENT);
                updateConfigurationFile(prop);
            }

            if (isSkipMojo()) {
                info("Skip execution.");
                trackMojoSkip();
            } else {
                trackMojoStart();

                doExecute();

                trackMojoSuccess();
            }
        } catch (Exception e) {
            handleException(e);
        } finally {
            // When maven goal executes too quick, The HTTPClient of AI SDK may not fully initialized and will step
            // into endless loop when close, we need to call it in main thread.
            // Refer here for detail codes: https://github.com/Microsoft/ApplicationInsights-Java/blob/master/core/src
            // /main/java/com/microsoft/applicationinsights/internal/channel/common/ApacheSender43.java#L103
            try {
                // Sleep to wait ai sdk flush telemetries
                Thread.sleep(2 * 1000);
            } catch (InterruptedException e) {
                // swallow this exception
            }
            ApacheSenderFactory.INSTANCE.create().close();
        }
    }
1241652
public void deployCron() throws MojoExecutionException {
    stager.stage();
    try {
      deployMojo
          .getAppEngineFactory()
          .deployment()
          .deployCron(
              configBuilder.buildDeployProjectConfigurationConfiguration(appengineDirectory));
    } catch (AppEngineException ex) {
      throw new MojoExecutionException("Failed to deploy", ex);
    }
  }
684723
public static Repository getJcrRepository(final FedoraRepository repository) {
        if (repository instanceof FedoraRepositoryImpl) {
            return ((FedoraRepositoryImpl)repository).getJcrRepository();
        }
        throw new ClassCastException("FedoraRepository is not a " + FedoraRepositoryImpl.class.getCanonicalName());
    }