Feed aggregator
Microsoft: Windows 24H2 Will Remove Cortana and WordPad Apps
Read more of this story at Slashdot.
Google's AI Feeds People Answers From The Onion
Read more of this story at Slashdot.
China Sets Up Third Fund With $47.5 Billion To Boost Semiconductor Sector
Read more of this story at Slashdot.
Company will Convert GM's Electric Vans into Speedy Mobile Superchargers for Fleets
Read more of this story at Slashdot.
Food Industry Launches 'Ferocious' Campaign Against Regulations on Ultraprocessed Foods
Read more of this story at Slashdot.
CodeSOD: Classic WTF: An Ant Pushes a Perl
It’s an old joke that Perl is a “write only language”. Despite some of its issues, back in the early 2000s, Perl was one of the best options out there for scripting languages and rapid-development automation.
Speaking of automation, build automation is really important. Back in the early 2000s, before Maven really caught on, your build automation tool for Java was Ant. Ant, like everything invented in the early 2000s, was driven by an XML scripting tool. Since it was tuned specifically for Java, it had some high-level operations to streamline tasks like generating proxy classes for calling web services based on a supplied WSDL file.
Actually, speaking of code generation, Carrie sends us this code block. It’s a Perl script that’s called from an Ant build. It runs after generating a class based off a WSDL. It parses Java code using Regular Expressions and injects a ListWrapper class which doesn’t adhere to the List contract. But hey, it does have a use strict declaration, guaranteeing you’ll get errors if you access uninitialized variables.
use strict; use warnings; my $dir = $ARGV[0]; readDir($dir); sub readDir { my ($dir) = @_; opendir my $dirHandle, $dir or die "Cannot open $dir.\n$!\n"; foreach my $file(readdir($dirHandle)) { next if $file =~ m/^\./; if(-d "$dir/$file") { readDir("$dir/$file"); next; } my %seenFields; my %multiples; my $fileName = "$dir/$file"; open IN, "<$fileName" or die "Cannot open $fileName.\n$!\n"; my @methods; my $file = ""; my $currentLine; my $containsContent = 0; while(<IN>) { if($_ =~ m/\@XmlElementRef\(name\s*=\s*"(.*?)".+namespace\s*=\s*"(.*?)".+type\s*=\s*(.*?.class)/) { my $field = ucfirst($1); my $namespace = $2; my $class = $3; $multiples{$1}++; if($multiples{$field} > 1) { $_ =~ s/name\s*=\s*"$1"/name = "$1$multiples{$1}"/gis; $field = $1 . $multiples{$1}; } my $fieldlc = lc($field); my $retObject = substr($class, 0, length($class) - 6); die if not defined $retObject; my $methodName = $field; unless(defined $seenFields{$methodName}) { $seenFields{$methodName} = 1; my $method = <<EOF; public List get$field() { List all = getContent(); ListWrapper retVal = new ListWrapper(all); for(java.lang.Object current : all) { java.lang.String className = null; if(current instanceof javax.xml.bind.JAXBElement) { className = ((javax.xml.bind.JAXBElement)current).getName().getLocalPart().toLowerCase(); } else { className = current.getClass().getSimpleName().toLowerCase(); } boolean good = false; if(className.equalsIgnoreCase("$fieldlc")) { good = true; } else { if(className.length() > 4) { className = className.substring(0, className.length() - 4); if(className.equalsIgnoreCase("$fieldlc")) { good = true; } } } if(good) { retVal.addWrapped(current); } } return retVal; } EOF push(@methods, $method); } } elsif ($_ =~ m/getContent\(\)/) { $containsContent = 1; } $currentLine = $_; $file .= $currentLine if defined $currentLine; } close IN; if($containsContent) { print "$fileName\n"; for my $method(@methods) { $file .= $method; } $file .= <<EOF; private class ListWrapper<T> extends ArrayList<T> { private List contentsList; public ListWrapper(List contents) { super(); contentsList = contents; } public boolean addWrapped(T toAdd) { return super.add(toAdd); } \@Override public boolean add(T toAdd) { return contentsList.add(toAdd); } \@Override public boolean addAll(java.util.Collection<? extends T> toAdd) { return contentsList.addAll(toAdd); } \@Override public T set(int index, T element) { int realIndex = contentsList.indexOf(this.get(index)); return (T)contentsList.set(realIndex, element); } } } EOF open OUT, ">$fileName" or die "Cannot open $fileName.\n$!\n"; print OUT $file; close OUT; } } closedir $dirHandle; } hljs.initHighlightingOnLoad(); [Advertisement] ProGet’s got you covered with security and access controls on your NuGet feeds. Learn more.1 in 9 American Kids Were Diagnosed With ADHD, New Study Finds
Read more of this story at Slashdot.
America Has One Public Charger for Every 20 Electric Cars
Read more of this story at Slashdot.
Pew Research Finds 64% of Americans Live Within Two Miles of a Public EV Charger
Read more of this story at Slashdot.
Technical Issues' Stall MLB's Adoption of Robots to Call Balls and Strikes
Read more of this story at Slashdot.
Memory Sealing 'mseal' System Call Merged For Linux 6.10
Read more of this story at Slashdot.
Mojo, Bend, and the Rise of AI-First Programming Languages
Read more of this story at Slashdot.
Could Sea Explosions Finally Locate the 2014 Crash Site of Flight MH370?
Read more of this story at Slashdot.
Netflix's Sci-Fi Movie 'Atlas': AI Apocalypse Blockbuster Gets 'Shocking' Reviews
Read more of this story at Slashdot.
Ubuntu 24.04 Now Runs on the Nintendo Switch (Unofficially)
Read more of this story at Slashdot.
Rust Foundation Reports 20% of Rust Crates Use 'Unsafe' Keyword
Read more of this story at Slashdot.
How A US Hospital is Using AI to Analyze X-Rays - With Help From Red Hat
Read more of this story at Slashdot.
VBScript's 'Deprecation' Confirmed by Microsoft - and Eventual Removal from Windows
Read more of this story at Slashdot.
A Startup's Faster-Than-E-Ink Android Tablet Challenges Apple's IPad
Read more of this story at Slashdot.
Trump Promises He'd Commute the Life Sentence of 'Silk Road' Founder Ross Ulbricht
Read more of this story at Slashdot.