M2ServletContextListener implements ServletContextListener { GAV deployJar(final String file) { GAV gav = new GAV(); Properties props = readZipFile(file); if (!props.isEmpty()) { gav = new GAV(props.getProperty(GROUP_ID), props.getProperty(ARTIFACT_ID), props.getProperty(VERSION)); deploy(gav, file); } return gav; } M2ServletContextListener(); @Override void contextInitialized(ServletContextEvent servletContextEvent); @Override void contextDestroyed(ServletContextEvent servletContextEvent); void deploy(final GAV gav,
                       final String jarPath);  }
@Test public void deployJarsFrowWar() throws Exception { RepositorySystemSession session = Aether.getAether().getSession(); assertThat(checksIfArtifactIsPresent(session)).isFalse(); File file = new File("target/test-classes/org/guvnor/m2repo/backend/server/uberfire-m2repo-editor-backend-100-SNAPSHOT.jar"); assertThat(file).exists(); M2ServletContextListener listener = new M2ServletContextListener(); GAV deployed = listener.deployJar(file.getAbsolutePath()); assertThat(deployed.getGroupId()).isEqualTo("org.uberfire"); assertThat(deployed.getArtifactId()).isEqualTo("uberfire-m2repo-editor-backend"); assertThat(deployed.getVersion()).isEqualTo("100-SNAPSHOT"); ArtifactRequest artifactRequest = new ArtifactRequest(); artifactRequest.setArtifact(getArtifact()); ArtifactResult result = Aether.getAether().getSystem().resolveArtifact(session, artifactRequest); assertThat(result.isMissing()).isFalse(); assertThat(result.isResolved()).isTrue(); String absolutePath = result.getArtifact().getFile().toString(); String folder = absolutePath.substring(0, absolutePath.lastIndexOf(File.separator)); File remoteRepos = new File(folder + File.separator + "_remote.repositories"); assertThat(remoteRepos.exists()).isTrue(); File metadata = new File(folder + File.separator + "maven-metadata-local.xml"); assertThat(metadata.exists()).isTrue(); File pom = new File(folder + File.separator + "uberfire-m2repo-editor-backend-100-SNAPSHOT.pom"); assertThat(pom.exists()).isTrue(); }