private static Tag newTag(String tagType, String tagID, UCMEntity entity, String cgi) throws TagException, UnableToCreateEntityException, UCMEntityNotFoundException, UnableToGetEntityException, UnableToInitializeEntityException { logger.fine("ENTITY=" + entity.toString()); logger.fine("CGI FOR NEW = " + cgi); // System.out.println( "CGI==="+cgi ); /* Delete any existing Tags with the unique ID */ logger.fine( "Deleting Tags with ID: " + tagType + tagID + " for entity " + entity.getFullyQualifiedName()); deleteTagsWithID(tagType, tagID, entity); cgi = "tagtype=" + tagType + "&tagid=" + tagID + (cgi.length() > 0 ? "&" + cgi : ""); String fqname = storeTag(entity, cgi); Tag tag = (Tag) UCMEntity.getEntity(Tag.class, fqname); // tag.SetEntry( "tagtype", tagType ); // tag.SetEntry( "tagid", tagID ); tag.setKeyValue(cgi); tag.setTagEntity(entity); return tag; }
private static Tag newTag(UCMEntity entity, String tagType, String tagID) throws UnableToInitializeEntityException { Tag tag = (Tag) UCMEntity.getEntity(Tag.class, "tag@0@" + entity.getPVob().getName()); // tag.SetEntry( "tagtype", tagType ); // tag.SetEntry( "tagid", tagID ); String cgi = "tagtype=" + tagType + "&tagid=" + tagID; tag.setKeyValue(cgi); tag.setTagEntity(entity); tag.setCreated(true); return tag; }
public static Activity get(String name, PVob pvob) throws UnableToInitializeEntityException { if (!name.startsWith("activity:")) { name = "activity:" + name; } Activity entity = (Activity) UCMEntity.getEntity(Activity.class, name + "@" + pvob); return entity; }
private static String storeTag(UCMEntity entity, String cgi) throws TagException { logger.fine(entity.getFullyQualifiedName()); String cmd = "mkhlink -ttext \"" + cgi + "\" " + __TAG_NAME + " " + entity; CmdResult res = null; try { res = Cleartool.run(cmd); } catch (AbnormalProcessTerminationException e) { logger.warning("Unable add tag: " + e.getMessage()); Matcher match = pattern_hlink_type_missing.matcher(e.getMessage()); if (match.find()) { logger.fine("Found match"); // UCM.addMessage( "The Hyperlink type \"" + match.group( 1 ) + "\" was not // found.\nInstallation: \"cleartool mkhltype " + __TAG_NAME + " -c \"Hyperlink type for // tagging entities\"\"" ); // throw new UCMException( "ClearCase hyperlink type \"" + match.group( 1 ) + "\" was not // found.", e.getMessage(), UCMType.UNKNOWN_HLINK_TYPE ); // UCMException ucme = new UCMException( "ClearCase hyperlink type \"" + match.group( 1 ) + // "\" was not found. ", e, UCMType.UNKNOWN_HLINK_TYPE ); // ucme.addInformation( "The Hyperlink type \"" + match.group( 1 ) + "\" was not // found.\nInstallation: \"cleartool mkhltype -global -c \"Hyperlink type for tagging // entities\" " + __TAG_NAME + "@" + match.group( 2 ) ); TagException te = new TagException(entity, cgi, __TAG_NAME, Type.NO_SUCH_HYPERLINK, e); te.addInformation( "The Hyperlink type \"" + match.group(1) + "\" was not found.\nInstallation: \"cleartool mkhltype -global -c \"Hyperlink type for tagging entities\" " + __TAG_NAME + "@" + match.group(2)); throw te; } else { // throw new UCMException( e ); throw new TagException(entity, cgi, __TAG_NAME, Type.CREATION_FAILED, e); } } String tag = res.stdoutBuffer.toString(); Matcher match = pattern_remove_verbose_tag.matcher(tag); if (!match.find()) { // throw new UCMException( "Could not create tag", UCMType.TAG_CREATION_FAILED ); throw new TagException(entity, cgi, __TAG_NAME, Type.CREATION_FAILED); } return match.group(1); }
public static List<Activity> parseActivityStrings(List<String> result, int length) throws UnableToLoadEntityException, UCMEntityNotFoundException, UnableToInitializeEntityException { ArrayList<Activity> activities = new ArrayList<Activity>(); Activity current = null; // System.out.println("PARSING:"); for (String s : result) { /* Get activity */ Matcher match = pattern_activity.matcher(s); /* This line is a new activity */ if (match.find()) { current = get(match.group(1)); /* A special case? */ if (current.getShortname().equals("no_activity")) { logger.debug("Recorded a special activity case"); current.setSpecialCase(true); } activities.add(current); continue; } if (current == null) { logger.debug("Not an activity: " + s); continue; } /* If not an activity, it must be a version */ String f = s.trim(); /* * If the version cannot be instantiated and is a special case, skip * it */ Version v = (Version) UCMEntity.getEntity(Version.class, f).load(); v.setSFile(v.getFile().getAbsolutePath().substring(length)); // System.out.println(f); current.changeset.versions.add(v); } return activities; }
public static Tag getTag(UCMEntity entity, String tagType, String tagID, boolean create) throws TagException, UnableToInitializeEntityException, UnableToCreateEntityException, UCMEntityNotFoundException, UnableToGetEntityException { logger.fine(entity.toString()); List<Tag> tags = getTags(entity); for (Tag t : tags) { logger.fine("Current: " + t); /* Is it the correct tag? Return it! */ if (t.getTagType().equals(tagType) && t.getTagID().equals(tagID)) { logger.fine("This is it!"); t.setTagEntity(entity); return t; } } logger.fine("Could not find the Tag with ID " + tagType + tagID + ". Creating new."); if (create) { return newTag(entity, tagType, tagID); } else { return null; } }
public static List<Tag> getTags(UCMEntity entity) throws TagException, UnableToInitializeEntityException { logger.fine(entity.toString()); String cmd = "describe -ahlink " + __TAG_NAME + " -l " + entity; CmdResult res = null; try { res = Cleartool.run(cmd); } catch (AbnormalProcessTerminationException e) { Matcher match = pattern_hlink_type_missing.matcher(e.getMessage()); logger.warning("Unable to get tags: " + e.getMessage()); if (match.find()) { logger.fine("Tag type not found"); // UCM.addMessage( "The Hyperlink type \"" + match.group( 1 ) + "\" was not // found.\nInstallation: \"cleartool mkhltype " + __TAG_NAME + " -c \"Hyperlink type for // tagging entities\"\"" ); // throw new UCMException( "ClearCase hyperlink type \"" + match.group( 1 ) + "\" was not // found. ", e.getMessage(), UCMType.UNKNOWN_HLINK_TYPE ); // UCMException ucme = new UCMException( "ClearCase hyperlink type \"" + match.group( 1 ) + // "\" was not found. ", e, UCMType.UNKNOWN_HLINK_TYPE ); // ucme.addInformation( "The Hyperlink type \"" + match.group( 1 ) + "\" was not // found.\nInstallation: \"cleartool mkhltype -global -c \"Hyperlink type for tagging // entities\" " + __TAG_NAME + "@" + match.group( 2 ) ); TagException te = new TagException(entity, "", __TAG_NAME, Type.NO_SUCH_HYPERLINK, e); te.addInformation( "The Hyperlink type \"" + match.group(1) + "\" was not found.\nInstallation: \"cleartool mkhltype -global -c \"Hyperlink type for tagging entities\" " + __TAG_NAME + "@" + match.group(2)); throw te; } else { logger.fine("Something else"); throw new TagException(entity, "", __TAG_NAME, Type.CREATION_FAILED, e); } } List<String> list = res.stdoutList; // List<Tuple<String, String>> tags = new ArrayList<Tuple<String, // String>>(); // List<String[]> tags = new ArrayList<String[]>(); ArrayList<Tag> tags = new ArrayList<Tag>(); /* There are tags */ if (list.size() > 2) { for (int i = 2; i < list.size(); i++) { logger.fine("[" + i + "]" + list.get(i)); Matcher match = pattern_tags.matcher(list.get(i)); if (match.find()) { // tags.add( new Tuple<String, String>( match.group( 1 ), // match.group( 2 ) ) ); // tags.add( new String[] { match.group( 1 ), match.group( 2 ) } ); Tag tag = (Tag) UCMEntity.getEntity(Tag.class, match.group(1).trim()); tag.setKeyValue(match.group(2)); tags.add(tag); } } } return tags; }