def testExclusion(self): pig = Artifact('org.apache.pig', 'pig', '0.8.3') exclusion = [Artifact(*x.split(":")) for x in ['ant:ant', 'junit:junit','org.eclipse.jdt:core']] artifacts = _resolve_artifacts([pig], exclusion) self.assertTrue(len(artifacts) > 0) self.assertFalse(any([x.is_same_artifact(Artifact('ant', 'ant')) for x in artifacts])) self.assertFalse(any([x.is_same_artifact(Artifact('junit', 'junit')) for x in artifacts])) self.assertFalse(any([x.is_same_artifact(Artifact('org.eclipse', 'core')) for x in artifacts]))
def requires_java(requires_info): global use_pom, dependencies, repositories, exclusions use_pom = False if 'repositories' in requires_info: repositories = requires_info['repositories'] if 'dependencies' in requires_info: dependencies = [Artifact(*d) for d in requires_info['dependencies']] if 'exclusions' in requires_info: exclusions = [Artifact(*d) for d in requires_info['exclusions']]
def update(artifact_id): """ Update a snapshot artifact, check for new version """ artifact = Artifact.from_id(artifact_id) artifact = index_manager.get_artifact(artifact) if artifact is None: logger.error('[Error] Can not update %s, please install it first' % artifact) sys.exit(1) if artifact.is_snapshot(): selected_repos = artifact.repos installed_file = os.path.join(get_lib_path(), artifact.to_jip_name()) if os.path.exists(installed_file): lm = os.stat(installed_file)[stat.ST_MTIME] ## find the repository contains the new release ts = selected_repos.last_modified(artifact) if ts is not None and ts > lm : ## download new jar selected_repos.download_jar(artifact, get_lib_path()) ## try to update dependencies pomstring = selected_repos.download_pom(artifact) pom = Pom(pomstring) dependencies = pom.get_dependencies() _install(dependencies) else: logger.error('[Error] Artifact not installed: %s' % artifact) sys.exit(1) else: logger.error('[Error] Can not update non-snapshot artifact') return
def update(artifact_id): """ Update a snapshot artifact, check for new version """ artifact = Artifact.from_id(artifact_id) artifact = index_manager.get_artifact(artifact) if artifact is None: logger.error('[Error] Can not update %s, please install it first' % artifact) sys.exit(1) if artifact.is_snapshot(): selected_repos = artifact.repos installed_file = os.path.join(get_lib_path(), artifact.to_jip_name()) if os.path.exists(installed_file): lm = os.stat(installed_file)[stat.ST_MTIME] ## find the repository contains the new release ts = selected_repos.last_modified(artifact) if ts is not None and ts > lm: ## download new jar selected_repos.download_jar(artifact, get_lib_path()) ## try to update dependencies pomstring = selected_repos.download_pom(artifact) pom = Pom(pomstring) dependencies = pom.get_dependencies() _install(dependencies) else: logger.error('[Error] Artifact not installed: %s' % artifact) sys.exit(1) else: logger.error('[Error] Can not update non-snapshot artifact') return
def _install(artifacts, exclusions=[], options={}): dryrun = options.get("dry-run", False) verify = not options.get("insecure", True) _exclusions = options.get('exclude', []) copy_pom = options.get('copy-pom', False) if _exclusions: _exclusions = map(lambda x: Artifact(*(x.split(":"))), _exclusions) exclusions.extend(_exclusions) download_list = _resolve_artifacts(artifacts, exclusions, verify) if not dryrun: ## download to cache first for artifact in download_list: if artifact.repos != cache_manager.as_repos(): artifact.repos.download_jar( artifact, cache_manager.get_jar_path(artifact), verify) pool.join() for artifact in download_list: cache_manager.get_artifact_jar(artifact, get_lib_path()) if copy_pom: cache_manager.get_artifact_pom(artifact, get_lib_path()) index_manager.commit() logger.info("[Finished] dependencies resolved") else: logger.info("[Install] Artifacts to install:") for artifact in download_list: logger.info(artifact)
def testExclusion(self): pig = Artifact('org.apache.pig', 'pig', '0.8.3') exclusion = map(lambda x: Artifact(*x.split(":")), ['ant:ant', 'junit:junit', 'org.eclipse.jdt:core']) print exclusion artifacts = _resolve_artifacts([pig], exclusion) print artifacts self.assert_(len(artifacts) > 0) self.assert_(not any( map(lambda x: x.is_same_artifact(Artifact('ant', 'ant')), artifacts))) self.assert_(not any( map(lambda x: x.is_same_artifact(Artifact('junit', 'junit')), artifacts))) self.assert_(not any( map(lambda x: x.is_same_artifact(Artifact('org.eclipse', 'core')), artifacts)))
def deps(artifact_id, options={}): """ Install dependencies for a given artifact coordinator """ artifact = Artifact.from_id(artifact_id) pominfo = _find_pom(artifact) if pominfo is not None: pom = Pom(pominfo[0]) _install(pom.get_dependencies(), options=options) else: logger.error('[Error] artifact %s not found in any repository' % artifact_id) sys.exit(1)
def testLocalDownloadOfPomWithUtfChars(self): with tmpdir() as temp_repo_dir: artifact_dir = "%s/dummygroup/dummyartifact/1.0.0/" % temp_repo_dir mkdir_p(artifact_dir) with open("%sdummyartifact-1.0.0.pom" % artifact_dir, "w") as f: f.write("\xe2") testee = MavenFileSystemRepos('dummy_name', temp_repo_dir) artifact = Artifact('dummygroup', 'dummyartifact', '1.0.0') pom = testee.download_pom(artifact) # should not raise an UnicodeDecodeError pom.encode("utf-8")
def remove(artifact_id): """ Remove an artifact from library path """ logger.info('[Checking] %s in library index' % artifact_id) artifact = Artifact.from_id(artifact_id) artifact_path = os.path.join(get_lib_path(), artifact.to_jip_name()) if index_manager.is_installed(artifact) and os.path.exists(artifact_path): os.remove(artifact_path) index_manager.remove_artifact(artifact) index_manager.commit() logger.info('[Finished] %s removed from library path' % artifact_id) else: logger.error('[Error] %s not installed' % artifact_id) sys.exit(1)
def require(artifact_id): _prepare() artifact = Artifact.from_id(artifact_id) artifact_set = _resolve_artifacts([artifact]) ## download to cache first for artifact in artifact_set: if artifact.repos != cache_manager.as_repos(): artifact.repos.download_jar(artifact, cache_manager.get_jar_path(artifact)) pool.join() ## append jars to path for artifact in artifact_set: sys.path.append(cache_manager.get_jar_path(artifact, filepath=True))
def testResolveArtifactWithUmlautsInPom(self): artifact = Artifact('de.l3s.boilerpipe', 'boilerpipe', '1.1.0') artifacts = _resolve_artifacts([artifact]) self.assertEqual(len(artifacts), 1)
def testResolve(self): junit = Artifact('junit', 'junit', '3.8.1') artifacts = _resolve_artifacts([junit]) self.assertEqual(len(artifacts), 1)
def testArtifact(self): commons_lang = Artifact('commons-lang', 'commons-lang', '2.6') self.assertEqual(str(commons_lang), 'commons-lang:commons-lang:2.6')
def testResolve(self): commons_lang = Artifact('commons-lang', 'commons-lang', '2.6') print commons_lang artifacts = _resolve_artifacts([commons_lang]) print artifacts self.assert_(len(artifacts) == 1)
def install(artifact_id, options={}): """ Install a package identified by "groupId:artifactId:version" """ artifact = Artifact.from_id(artifact_id) _install([artifact], options=options)