@Test public void fetchModelFromRemoteExceptionTest() { String groupId = "junit"; String artifactId = "junit"; String version = "4.12.123123"; PomModel pomModel = new PomModel(groupId, artifactId, version); TUExecutionResult executionResult = pomModel.execution(transformedAppFolder, transformationContext); assertEquals(executionResult.getType(), TUExecutionResult.Type.ERROR); assertEquals(executionResult.getException().getClass(), TransformationUtilityException.class); assertEquals(executionResult.getException().getMessage(), "The specified file could not be found or read and parsed as valid Maven pom file"); }
@Override protected TUExecutionResult execution(File transformedAppFolder, TransformationContext transformationContext) { Model model; try { URL mavenArtifactUrl; if (StringUtils.isNotBlank(groupId) && StringUtils.isNotBlank(artifactId) && StringUtils.isNotBlank(version)) { mavenArtifactUrl = new URL(String.format("%s/%s/%s/%s/%s-%s.pom", repoURI, groupId, artifactId, version, artifactId, version)); } else if (wasFileExplicitlySet()) { File localPomFile = getAbsoluteFile(transformedAppFolder, transformationContext); mavenArtifactUrl = localPomFile.toURI().toURL(); } else { return TUExecutionResult.error(this, new TransformationUtilityException("Maven coordinates are missing and local file was not set")); } try (BufferedInputStream inputStream = new BufferedInputStream(mavenArtifactUrl.openStream())) { model = new MavenXpp3Reader().read(inputStream); } if (model == null) { return TUExecutionResult.error(this, new TransformationUtilityException("Returned maven model is null")); } } catch (IOException | XmlPullParserException e) { return TUExecutionResult.error(this, new TransformationUtilityException("The specified file could not be found or read and parsed as valid Maven pom file", e)); } return TUExecutionResult.value(this, model); }
PomModel extends TransformationUtility<PomModel> { @Override protected TUExecutionResult execution(File transformedAppFolder, TransformationContext transformationContext) { Model model; try { URL mavenArtifactUrl; if (StringUtils.isNotBlank(groupId) && StringUtils.isNotBlank(artifactId) && StringUtils.isNotBlank(version)) { mavenArtifactUrl = new URL(String.format("%s/%s/%s/%s/%s-%s.pom", repoURI, groupId, artifactId, version, artifactId, version)); } else if (wasFileExplicitlySet()) { File localPomFile = getAbsoluteFile(transformedAppFolder, transformationContext); mavenArtifactUrl = localPomFile.toURI().toURL(); } else { return TUExecutionResult.error(this, new TransformationUtilityException("Maven coordinates are missing and local file was not set")); } try (BufferedInputStream inputStream = new BufferedInputStream(mavenArtifactUrl.openStream())) { model = new MavenXpp3Reader().read(inputStream); } if (model == null) { return TUExecutionResult.error(this, new TransformationUtilityException("Returned maven model is null")); } } catch (IOException | XmlPullParserException e) { return TUExecutionResult.error(this, new TransformationUtilityException("The specified file could not be found or read and parsed as valid Maven pom file", e)); } return TUExecutionResult.value(this, model); } }
PomModel extends TransformationUtility<PomModel> { @Override protected TUExecutionResult execution(File transformedAppFolder, TransformationContext transformationContext) { Model model; try { URL mavenArtifactUrl; if (StringUtils.isNotBlank(groupId) && StringUtils.isNotBlank(artifactId) && StringUtils.isNotBlank(version)) { mavenArtifactUrl = new URL(String.format("%s/%s/%s/%s/%s-%s.pom", repoURI, groupId, artifactId, version, artifactId, version)); } else if (wasFileExplicitlySet()) { File localPomFile = getAbsoluteFile(transformedAppFolder, transformationContext); mavenArtifactUrl = localPomFile.toURI().toURL(); } else { return TUExecutionResult.error(this, new TransformationUtilityException("Maven coordinates are missing and local file was not set")); } try (BufferedInputStream inputStream = new BufferedInputStream(mavenArtifactUrl.openStream())) { model = new MavenXpp3Reader().read(inputStream); } if (model == null) { return TUExecutionResult.error(this, new TransformationUtilityException("Returned maven model is null")); } } catch (IOException | XmlPullParserException e) { return TUExecutionResult.error(this, new TransformationUtilityException("The specified file could not be found or read and parsed as valid Maven pom file", e)); } return TUExecutionResult.value(this, model); } PomModel();  PomModel(String groupId, String artifactId, String version);  PomModel(String groupId, String artifactId, String version, String repoURI); }
PomModel extends TransformationUtility<PomModel> { @Override protected TUExecutionResult execution(File transformedAppFolder, TransformationContext transformationContext) { Model model; try { URL mavenArtifactUrl; if (StringUtils.isNotBlank(groupId) && StringUtils.isNotBlank(artifactId) && StringUtils.isNotBlank(version)) { mavenArtifactUrl = new URL(String.format("%s/%s/%s/%s/%s-%s.pom", repoURI, groupId, artifactId, version, artifactId, version)); } else if (wasFileExplicitlySet()) { File localPomFile = getAbsoluteFile(transformedAppFolder, transformationContext); mavenArtifactUrl = localPomFile.toURI().toURL(); } else { return TUExecutionResult.error(this, new TransformationUtilityException("Maven coordinates are missing and local file was not set")); } try (BufferedInputStream inputStream = new BufferedInputStream(mavenArtifactUrl.openStream())) { model = new MavenXpp3Reader().read(inputStream); } if (model == null) { return TUExecutionResult.error(this, new TransformationUtilityException("Returned maven model is null")); } } catch (IOException | XmlPullParserException e) { return TUExecutionResult.error(this, new TransformationUtilityException("The specified file could not be found or read and parsed as valid Maven pom file", e)); } return TUExecutionResult.value(this, model); } PomModel();  PomModel(String groupId, String artifactId, String version);  PomModel(String groupId, String artifactId, String version, String repoURI); PomModel setArtifact(String artifactInfo); PomModel setGroupId(String groupId); String getGroupId(); PomModel setArtifactId(String artifactId); String getArtifactId(); PomModel setVersion(String version); String getVersion(); PomModel setRepoURI(String repoURI); String getRepoURI(); @Override String getDescription(); }
PomModel extends TransformationUtility<PomModel> { @Override protected TUExecutionResult execution(File transformedAppFolder, TransformationContext transformationContext) { Model model; try { URL mavenArtifactUrl; if (StringUtils.isNotBlank(groupId) && StringUtils.isNotBlank(artifactId) && StringUtils.isNotBlank(version)) { mavenArtifactUrl = new URL(String.format("%s/%s/%s/%s/%s-%s.pom", repoURI, groupId, artifactId, version, artifactId, version)); } else if (wasFileExplicitlySet()) { File localPomFile = getAbsoluteFile(transformedAppFolder, transformationContext); mavenArtifactUrl = localPomFile.toURI().toURL(); } else { return TUExecutionResult.error(this, new TransformationUtilityException("Maven coordinates are missing and local file was not set")); } try (BufferedInputStream inputStream = new BufferedInputStream(mavenArtifactUrl.openStream())) { model = new MavenXpp3Reader().read(inputStream); } if (model == null) { return TUExecutionResult.error(this, new TransformationUtilityException("Returned maven model is null")); } } catch (IOException | XmlPullParserException e) { return TUExecutionResult.error(this, new TransformationUtilityException("The specified file could not be found or read and parsed as valid Maven pom file", e)); } return TUExecutionResult.value(this, model); } PomModel();  PomModel(String groupId, String artifactId, String version);  PomModel(String groupId, String artifactId, String version, String repoURI); PomModel setArtifact(String artifactInfo); PomModel setGroupId(String groupId); String getGroupId(); PomModel setArtifactId(String artifactId); String getArtifactId(); PomModel setVersion(String version); String getVersion(); PomModel setRepoURI(String repoURI); String getRepoURI(); @Override String getDescription();  }