Skip to content
This repository has been archived by the owner on Apr 13, 2023. It is now read-only.

Commit

Permalink
Now validate import namespaces against the currently configured repos…
Browse files Browse the repository at this point in the history
…itories (see also #6367)
  • Loading branch information
quintesse committed Jul 10, 2016
1 parent 4ca68a0 commit 3662bcf
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -239,4 +239,9 @@ public interface RepositoryManager {
void refresh(boolean recurse);

Overrides getOverrides();

/**
* Determines if the given namespace is recognized by any of the configured repositories
*/
boolean isValidNamespace(String namespace);
}
Original file line number Diff line number Diff line change
Expand Up @@ -599,4 +599,16 @@ public void refresh(boolean recurse) {
root.refresh(recurse);
}
}

@Override
public boolean isValidNamespace(String namespace) {
for (CmrRepository root : getRepositories()) {
if (namespace == null && DefaultRepository.NAMESPACE.equals(root.getNamespace())) {
return true;
} else if (namespace != null && namespace.equals(root.getNamespace())) {
return true;
}
}
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,9 @@ public void refresh(boolean recurse) {
public ArtifactContext getArtifactOverride(ArtifactContext context) throws RepositoryException {
return context;
}

@Override
public boolean isValidNamespace(String namespace) {
return namespace == null || DefaultRepository.NAMESPACE.equals(namespace);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -254,21 +254,30 @@ private void resolveModuleIfRequired(Module module, boolean forCompiledModule, M
} else {
//try and load the module from the repository
RepositoryManager repositoryManager = context.getRepositoryManager();
Exception exceptionOnGetArtifact = null;
Iterable<String> searchedArtifactExtensions = moduleManager.getSearchedArtifactExtensions();
ArtifactContext artifactContext = new ArtifactContext(moduleImport.getNamespace(), module.getNameAsString(), module.getVersion(), getArtifactSuffixes(searchedArtifactExtensions));
listener.retrievingModuleArtifact(module, artifactContext);
try {
artifact = repositoryManager.getArtifactResult(artifactContext);
} catch (Exception e) {
exceptionOnGetArtifact = catchIfPossible(e);
}
if (artifact == null) {
//not there => error
ModuleHelper.buildErrorOnMissingArtifact(artifactContext, module, moduleImport, dependencyTree, exceptionOnGetArtifact, moduleManagerUtil);
listener.retrievingModuleArtifactFailed(module, artifactContext);
}else{
listener.retrievingModuleArtifactSuccess(module, artifact);
if (repositoryManager.isValidNamespace(moduleImport.getNamespace())) {
Exception exceptionOnGetArtifact = null;
Iterable<String> searchedArtifactExtensions = moduleManager.getSearchedArtifactExtensions();
ArtifactContext artifactContext = new ArtifactContext(moduleImport.getNamespace(), module.getNameAsString(), module.getVersion(), getArtifactSuffixes(searchedArtifactExtensions));
listener.retrievingModuleArtifact(module, artifactContext);
try {
artifact = repositoryManager.getArtifactResult(artifactContext);
} catch (Exception e) {
exceptionOnGetArtifact = catchIfPossible(e);
}
if (artifact == null) {
//not there => error
ModuleHelper.buildErrorOnMissingArtifact(artifactContext, module, moduleImport, dependencyTree, exceptionOnGetArtifact, moduleManagerUtil);
listener.retrievingModuleArtifactFailed(module, artifactContext);
}else{
listener.retrievingModuleArtifactSuccess(module, artifact);
}
} else {
String msg = "unknown import namespace: '" + moduleImport.getNamespace() +
"', make sure the proper repository has been enabled";
if (!"maven".equals(moduleImport.getNamespace())) {
msg += " (if this is a Maven import make sure to add a 'maven:' prefix)";
}
moduleManagerUtil.attachErrorToDependencyDeclaration(moduleImport, dependencyTree, msg);
}
alreadySearchedArtifacts.put(module, artifact);
firstTime = true;
Expand Down

0 comments on commit 3662bcf

Please sign in to comment.