Skip to content

More specific exception handling #1285

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ private PlexusContainer createPlexusContainer() {
public void stop() {
try {
plexus.dispose();
} catch (Exception ex) {
} catch (RuntimeException ex) {
// ignore
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,10 +285,8 @@ public ScmFileSet getFileSet() throws IOException {
}

public ScmRepository getScmRepository() throws ScmException {
ScmRepository repository;

try {
repository = getScmManager().makeScmRepository(getConnectionUrl());
ScmRepository repository = getScmManager().makeScmRepository(getConnectionUrl());

ScmProviderRepository providerRepo = repository.getProviderRepository();

Expand Down Expand Up @@ -334,19 +332,18 @@ public ScmRepository getScmRepository() throws ScmException {

svnRepo.setTagBase(tagBase);
}

return repository;
} catch (ScmRepositoryException e) {
if (!e.getValidationMessages().isEmpty()) {
for (String message : e.getValidationMessages()) {
getLog().error(message);
}
}

throw new ScmException("Can't load the scm provider.", e);
} catch (Exception e) {
} catch (RuntimeException e) {
throw new ScmException("Can't load the scm provider.", e);
}

return repository;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package org.apache.maven.scm.provider.local.command.list;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

Expand Down Expand Up @@ -77,14 +78,14 @@ protected ListScmResult executeListCommand(

return new LocalListScmResult(null, files);
}
} catch (Exception e) {
} catch (IOException e) {
return new ListScmResult(null, "The svn command failed.", e.getMessage(), false);
}
}

private List<ScmFile> getFiles(File source, File directory, boolean recursive) throws Exception {
private List<ScmFile> getFiles(File source, File directory, boolean recursive) throws IOException {
if (!directory.exists()) {
throw new Exception("Directory '" + directory.getAbsolutePath() + "' doesn't exist.");
throw new IOException("Directory '" + directory.getAbsolutePath() + "' doesn't exist.");
}

List<ScmFile> files = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ private List<String> getConfLines() {
new BufferedReader(new FileReader(new File(getConfigDirectory(), "config")))) {
String line;
while ((line = reader.readLine()) != null) {
if (!line.startsWith("#") && (line != null && !line.isEmpty())) {
if (!line.startsWith("#") && !line.isEmpty()) {
lines.add(line);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package org.apache.maven.scm.provider.git.jgit.command.add;

import java.io.IOException;
import java.util.List;

import org.apache.maven.scm.ScmException;
Expand All @@ -30,6 +31,7 @@
import org.apache.maven.scm.provider.git.command.GitCommand;
import org.apache.maven.scm.provider.git.jgit.command.JGitUtils;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.errors.GitAPIException;

/**
* @author <a href="mailto:struberg@yahoo.de">Mark Struberg</a>
Expand Down Expand Up @@ -60,7 +62,7 @@ protected ScmResult executeAddCommand(

return new AddScmResult("JGit add", addedFiles);

} catch (Exception e) {
} catch (IOException | GitAPIException e) {
throw new ScmException("JGit add failure!", e);
} finally {
JGitUtils.closeRepo(git);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package org.apache.maven.scm.provider.git.jgit.command.blame;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

Expand All @@ -31,6 +32,7 @@
import org.apache.maven.scm.provider.git.command.GitCommand;
import org.apache.maven.scm.provider.git.jgit.command.JGitUtils;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.blame.BlameResult;

/**
Expand Down Expand Up @@ -61,7 +63,7 @@ public BlameScmResult executeBlameCommand(ScmProviderRepository repo, ScmFileSet
}

return new BlameScmResult("JGit blame", lines);
} catch (Exception e) {
} catch (IOException | GitAPIException e) {
throw new ScmException("JGit blame failure!", e);
} finally {
JGitUtils.closeRepo(git);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package org.apache.maven.scm.provider.git.jgit.command.branch;

import java.io.IOException;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.HashSet;
Expand Down Expand Up @@ -134,7 +135,7 @@ protected ScmResult executeBranchCommand(
} catch (PushException e) {
logger.debug("Failed to push branch", e);
return new BranchScmResult("JGit branch", "Failed to push changes: " + e.getMessage(), "", false);
} catch (Exception e) {
} catch (IOException | GitAPIException e) {
throw new ScmException("JGit branch failed!", e);
} finally {
JGitUtils.closeRepo(git);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ protected ChangeLogScmResult executeChangeLogCommand(
changeLogSet.setEndVersion(endVersion);

return new ChangeLogScmResult("JGit changelog", changeLogSet);
} catch (Exception e) {
} catch (IOException e) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

throw new ScmException("JGit changelog failure!", e);
} finally {
JGitUtils.closeRepo(git);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package org.apache.maven.scm.provider.git.jgit.command.checkin;

import java.io.File;
import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Collections;
Expand Down Expand Up @@ -50,6 +51,7 @@
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.Status;
import org.eclipse.jgit.api.TransportConfigCallback;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.UserConfig;
import org.eclipse.jgit.revwalk.RevCommit;
Expand Down Expand Up @@ -189,7 +191,7 @@ public CheckInScmResult executeCommand(ScmProviderRepository repo, ScmFileSet fi
} catch (PushException e) {
logger.debug("Failed to push commits", e);
return new CheckInScmResult("JGit checkin", "Failed to push changes: " + e.getMessage(), "", false);
} catch (Exception e) {
} catch (IOException | GitAPIException e) {
throw new ScmException("JGit checkin failure!", e);
} finally {
JGitUtils.closeRepo(git);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package org.apache.maven.scm.provider.git.jgit.command.checkout;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
Expand Down Expand Up @@ -48,6 +49,7 @@
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.PullCommand;
import org.eclipse.jgit.api.TransportConfigCallback;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.ProgressMonitor;
import org.eclipse.jgit.revwalk.RevCommit;
Expand Down Expand Up @@ -194,21 +196,20 @@ && new File(fileSet.getBasedir(), ".git").exists()
RevCommit commit = revWalk.parseCommit(git.getRepository().resolve(Constants.HEAD));
revWalk.close();

final TreeWalk walk = new TreeWalk(git.getRepository());
walk.reset(); // drop the first empty tree, which we do not need here
walk.setRecursive(true);
walk.addTree(commit.getTree());
try (TreeWalk walk = new TreeWalk(git.getRepository())) {
walk.reset(); // drop the first empty tree, which we do not need here
walk.setRecursive(true);
walk.addTree(commit.getTree());

List<ScmFile> listedFiles = new ArrayList<>();
while (walk.next()) {
listedFiles.add(new ScmFile(walk.getPathString(), ScmFileStatus.CHECKED_OUT));
}
walk.close();

logger.debug("current branch: " + git.getRepository().getBranch());
List<ScmFile> listedFiles = new ArrayList<>();
while (walk.next()) {
listedFiles.add(new ScmFile(walk.getPathString(), ScmFileStatus.CHECKED_OUT));
}
logger.debug("current branch: " + git.getRepository().getBranch());

return new CheckOutScmResult("checkout via JGit", listedFiles);
} catch (Exception e) {
return new CheckOutScmResult("checkout via JGit", listedFiles);
}
} catch (RuntimeException | IOException | GitAPIException e) {
throw new ScmException("JGit checkout failure!", e);
} finally {
JGitUtils.closeRepo(git);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ protected DiffScmResult executeDiffCommand(
DiffScmResult diff = callDiff(git, startRevision, endRevision);
git.getRepository().close();
return diff;
} catch (Exception e) {
} catch (IOException | GitAPIException e) {
throw new ScmException("JGit diff failure!", e);
} finally {
JGitUtils.closeRepo(git);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ protected ScmResult executeCommand(
}
}
return new InfoScmResult(infoItems, new ScmResult("JGit.resolve(HEAD)", "", objectId.toString(), true));
} catch (Exception e) {
} catch (IOException e) {
throw new ScmException("JGit resolve failure!", e);
} finally {
JGitUtils.closeRepo(git);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package org.apache.maven.scm.provider.git.jgit.command.list;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
Expand All @@ -37,6 +38,7 @@
import org.apache.maven.scm.provider.git.jgit.command.ScmProviderAwareSshdSessionFactory;
import org.apache.maven.scm.provider.git.repository.GitScmProviderRepository;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.transport.CredentialsProvider;
import org.slf4j.Logger;
Expand Down Expand Up @@ -82,7 +84,7 @@ protected ListScmResult executeListCommand(
}

return new ListScmResult("JGit ls-remote", list);
} catch (Exception e) {
} catch (IOException | GitAPIException e) {
throw new ScmException("JGit ls-remote failure!", e);
} finally {
JGitUtils.closeRepo(git);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package org.apache.maven.scm.provider.git.jgit.command.remoteinfo;

import java.io.IOException;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
Expand All @@ -36,6 +37,7 @@
import org.apache.maven.scm.provider.git.repository.GitScmProviderRepository;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.LsRemoteCommand;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.transport.CredentialsProvider;
Expand Down Expand Up @@ -92,7 +94,7 @@ public RemoteInfoScmResult executeRemoteInfoCommand(
}

return new RemoteInfoScmResult("JGit remoteinfo", heads, tag);
} catch (Exception e) {
} catch (IOException | GitAPIException e) {
throw new ScmException("JGit remoteinfo failure!", e);
} finally {
JGitUtils.closeRepo(git);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package org.apache.maven.scm.provider.git.jgit.command.remove;

import java.io.IOException;
import java.util.List;

import org.apache.maven.scm.ScmException;
Expand All @@ -30,6 +31,7 @@
import org.apache.maven.scm.provider.git.command.GitCommand;
import org.apache.maven.scm.provider.git.jgit.command.JGitUtils;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.errors.GitAPIException;

/**
* @author Georg Tsakumagos
Expand Down Expand Up @@ -58,7 +60,7 @@ protected ScmResult executeRemoveCommand(ScmProviderRepository repository, ScmFi

return new RemoveScmResult("JGit remove", removedFiles);

} catch (Exception e) {
} catch (IOException | GitAPIException e) {
throw new ScmException("JGit remove failure!", e);
} finally {
JGitUtils.closeRepo(git);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package org.apache.maven.scm.provider.git.jgit.command.status;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
Expand All @@ -33,6 +34,7 @@
import org.apache.maven.scm.provider.git.jgit.command.JGitUtils;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.Status;
import org.eclipse.jgit.api.errors.GitAPIException;

/**
* @author <a href="mailto:struberg@yahoo.de">Mark Struberg</a>
Expand All @@ -51,7 +53,7 @@ protected StatusScmResult executeStatusCommand(ScmProviderRepository repo, ScmFi
List<ScmFile> changedFiles = getFileStati(status);

return new StatusScmResult("JGit status", changedFiles);
} catch (Exception e) {
} catch (IOException | GitAPIException e) {
throw new ScmException("JGit status failure!", e);
} finally {
JGitUtils.closeRepo(git);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package org.apache.maven.scm.provider.git.jgit.command.tag;

import java.io.IOException;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.List;
Expand All @@ -42,6 +43,7 @@
import org.apache.maven.scm.provider.git.repository.GitScmProviderRepository;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.TransportConfigCallback;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.revwalk.RevCommit;
Expand Down Expand Up @@ -138,7 +140,7 @@ public ScmResult executeTagCommand(
} catch (PushException e) {
logger.debug("Failed to push tag", e);
return new TagScmResult("JGit tag", "Failed to push tag: " + e.getMessage(), "", false);
} catch (Exception e) {
} catch (IOException | GitAPIException e) {
throw new ScmException("JGit tag failure!", e);
} finally {
JGitUtils.closeRepo(git);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package org.apache.maven.scm.provider.git.jgit.command.untag;

import java.io.IOException;
import java.util.Collection;
import java.util.EnumSet;
import java.util.Optional;
Expand All @@ -39,6 +40,7 @@
import org.apache.maven.scm.provider.git.repository.GitScmProviderRepository;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.TransportConfigCallback;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.transport.PushResult;
import org.eclipse.jgit.transport.RefSpec;
Expand Down Expand Up @@ -112,7 +114,7 @@ protected ScmResult executeUntagCommand(
} catch (PushException e) {
logger.debug("Failed to push tag deletion", e);
return new UntagScmResult("JGit tagDelete", "Failed to push tag deletion: " + e.getMessage(), "", false);
} catch (Exception e) {
} catch (IOException | GitAPIException e) {
throw new ScmException("JGit tagDelete failure!", e);
} finally {
JGitUtils.closeRepo(git);
Expand Down
Loading