use of org.apache.maven.model.io.xpp3.MavenXpp3Reader in project zeppelin by apache.
the class SparkIntegrationTest method testInterpreterBasics.
private void testInterpreterBasics() throws IOException, InterpreterException, XmlPullParserException {
// add jars & packages for testing
InterpreterSetting sparkInterpreterSetting = interpreterSettingManager.getInterpreterSettingByName("spark");
sparkInterpreterSetting.setProperty("spark.jars.packages", "com.maxmind.geoip2:geoip2:2.5.0");
sparkInterpreterSetting.setProperty("SPARK_PRINT_LAUNCH_COMMAND", "true");
sparkInterpreterSetting.setProperty("zeppelin.python.gatewayserver_address", "127.0.0.1");
MavenXpp3Reader reader = new MavenXpp3Reader();
Model model = reader.read(new FileReader("pom.xml"));
sparkInterpreterSetting.setProperty("spark.jars", new File("target/zeppelin-interpreter-integration-" + model.getVersion() + ".jar").getAbsolutePath());
// test SparkInterpreter
Interpreter sparkInterpreter = interpreterFactory.getInterpreter("spark.spark", new ExecutionContext("user1", "note1", "test"));
InterpreterContext context = new InterpreterContext.Builder().setNoteId("note1").setParagraphId("paragraph_1").build();
InterpreterResult interpreterResult = sparkInterpreter.interpret("sc.version", context);
assertEquals(interpreterResult.toString(), InterpreterResult.Code.SUCCESS, interpreterResult.code());
String detectedSparkVersion = interpreterResult.message().get(0).getData();
assertTrue(detectedSparkVersion + " doesn't contain " + this.sparkVersion, detectedSparkVersion.contains(this.sparkVersion));
interpreterResult = sparkInterpreter.interpret("sc.range(1,10).sum()", context);
assertEquals(interpreterResult.toString(), InterpreterResult.Code.SUCCESS, interpreterResult.code());
assertTrue(interpreterResult.toString(), interpreterResult.message().get(0).getData().contains("45"));
interpreterResult = sparkInterpreter.interpret("sc.getConf.get(\"spark.user.name\")", context);
assertEquals(interpreterResult.toString(), InterpreterResult.Code.SUCCESS, interpreterResult.code());
assertTrue(interpreterResult.toString(), interpreterResult.message().get(0).getData().contains("user1"));
// test jars & packages can be loaded correctly
interpreterResult = sparkInterpreter.interpret("import org.apache.zeppelin.interpreter.integration.DummyClass\n" + "import com.maxmind.geoip2._", context);
assertEquals(interpreterResult.toString(), InterpreterResult.Code.SUCCESS, interpreterResult.code());
// test PySparkInterpreter
Interpreter pySparkInterpreter = interpreterFactory.getInterpreter("spark.pyspark", new ExecutionContext("user1", "note1", "test"));
interpreterResult = pySparkInterpreter.interpret("sqlContext.createDataFrame([(1,'a'),(2,'b')], ['id','name']).registerTempTable('test')", context);
assertEquals(interpreterResult.toString(), InterpreterResult.Code.SUCCESS, interpreterResult.code());
// test IPySparkInterpreter
Interpreter ipySparkInterpreter = interpreterFactory.getInterpreter("spark.ipyspark", new ExecutionContext("user1", "note1", "test"));
interpreterResult = ipySparkInterpreter.interpret("sqlContext.table('test').show()", context);
assertEquals(interpreterResult.toString(), InterpreterResult.Code.SUCCESS, interpreterResult.code());
// test SparkSQLInterpreter
Interpreter sqlInterpreter = interpreterFactory.getInterpreter("spark.sql", new ExecutionContext("user1", "note1", "test"));
interpreterResult = sqlInterpreter.interpret("select count(1) as c from test", context);
assertEquals(interpreterResult.toString(), InterpreterResult.Code.SUCCESS, interpreterResult.code());
assertEquals(interpreterResult.toString(), InterpreterResult.Type.TABLE, interpreterResult.message().get(0).getType());
assertEquals(interpreterResult.toString(), "c\n2\n", interpreterResult.message().get(0).getData());
// test SparkRInterpreter
Interpreter sparkrInterpreter = interpreterFactory.getInterpreter("spark.r", new ExecutionContext("user1", "note1", "test"));
if (isSpark2() || isSpark3()) {
interpreterResult = sparkrInterpreter.interpret("df <- as.DataFrame(faithful)\nhead(df)", context);
} else {
interpreterResult = sparkrInterpreter.interpret("df <- createDataFrame(sqlContext, faithful)\nhead(df)", context);
}
assertEquals(interpreterResult.toString(), InterpreterResult.Code.SUCCESS, interpreterResult.code());
assertEquals(interpreterResult.toString(), InterpreterResult.Type.TEXT, interpreterResult.message().get(0).getType());
assertTrue(interpreterResult.toString(), interpreterResult.message().get(0).getData().contains("eruptions waiting"));
}
use of org.apache.maven.model.io.xpp3.MavenXpp3Reader in project morphia by mongodb.
the class MorphiaVersionTest method testVersion.
@Test
public void testVersion() throws Exception {
MavenXpp3Reader reader = new MavenXpp3Reader();
Model model = reader.read(new FileReader("../pom.xml"));
Version version = Version.valueOf(model.getVersion());
String minorVersion = format("%s%s", version.getMajorVersion(), version.getMinorVersion());
// noinspection MisorderedAssertEqualsArguments
assertEquals(MorphiaVersion23.class.getSimpleName().replaceAll("\\D", ""), minorVersion);
}
use of org.apache.maven.model.io.xpp3.MavenXpp3Reader in project maven-plugins by apache.
the class AnalyzeDuplicateMojo method execute.
/**
* {@inheritDoc}
*/
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
if (skip) {
getLog().info("Skipping plugin execution");
return;
}
MavenXpp3Reader pomReader = new MavenXpp3Reader();
Model model = null;
Reader reader = null;
try {
reader = ReaderFactory.newXmlReader(project.getFile());
model = pomReader.read(reader);
reader.close();
reader = null;
} catch (Exception e) {
throw new MojoExecutionException("IOException: " + e.getMessage(), e);
} finally {
IOUtil.close(reader);
}
Set<String> duplicateDependencies = Collections.emptySet();
if (model.getDependencies() != null) {
duplicateDependencies = findDuplicateDependencies(model.getDependencies());
}
Set<String> duplicateDependenciesManagement = Collections.emptySet();
if (model.getDependencyManagement() != null && model.getDependencyManagement().getDependencies() != null) {
duplicateDependenciesManagement = findDuplicateDependencies(model.getDependencyManagement().getDependencies());
}
if (getLog().isInfoEnabled()) {
StringBuilder sb = new StringBuilder();
if (!duplicateDependencies.isEmpty()) {
sb.append("List of duplicate dependencies defined in <dependencies/> in your pom.xml:\n");
for (Iterator<String> it = duplicateDependencies.iterator(); it.hasNext(); ) {
String dup = it.next();
sb.append("\to ").append(dup);
if (it.hasNext()) {
sb.append("\n");
}
}
}
if (!duplicateDependenciesManagement.isEmpty()) {
if (sb.length() > 0) {
sb.append("\n");
}
sb.append("List of duplicate dependencies defined in <dependencyManagement/> in your pom.xml:\n");
for (Iterator<String> it = duplicateDependenciesManagement.iterator(); it.hasNext(); ) {
String dup = it.next();
sb.append("\to ").append(dup);
if (it.hasNext()) {
sb.append("\n");
}
}
}
if (sb.length() > 0) {
getLog().info(sb.toString());
} else {
getLog().info("No duplicate dependencies found in <dependencies/> or in <dependencyManagement/>");
}
}
}
use of org.apache.maven.model.io.xpp3.MavenXpp3Reader in project maven-plugins by apache.
the class PomUtils method loadPom.
/**
* Loads the (raw) model from the specified POM file.
*
* @param pomFile The path to the POM file to load, must not be <code>null</code>.
* @return The raw model, never <code>null</code>.
* @throws MojoExecutionException If the POM file could not be loaded.
*/
public static Model loadPom(File pomFile) throws MojoExecutionException {
Reader reader = null;
try {
reader = ReaderFactory.newXmlReader(pomFile);
final Model model = new MavenXpp3Reader().read(reader, false);
reader.close();
reader = null;
return model;
} catch (XmlPullParserException e) {
throw new MojoExecutionException("Failed to parse POM: " + pomFile, e);
} catch (IOException e) {
throw new MojoExecutionException("Failed to read POM: " + pomFile, e);
} finally {
IOUtil.close(reader);
}
}
use of org.apache.maven.model.io.xpp3.MavenXpp3Reader in project maven-plugins by apache.
the class Project001Stub method readModelFromFile.
static Model readModelFromFile(File file) throws IOException, XmlPullParserException {
MavenXpp3Reader pomReader = new MavenXpp3Reader();
XmlStreamReader reader = null;
try {
reader = ReaderFactory.newXmlReader(file);
final Model model = pomReader.read(reader);
reader.close();
reader = null;
return model;
} finally {
IOUtil.close(reader);
}
}
Aggregations